I am trying to select multiple fields from a case statement. I know the below syntax is wrong, but it describes what I am trying to do. Drawing particular attention to the CASE statement and the @type variable. Am I on the right track and if Im not some helpful poiters in the right direction would be appreciated.
Select
(tasks.id) As 'id',
(tasks.Title) As 'title',
(Excursions.ExcursionsColour) As 'backgroundColor',
(Excursions.ExcursionsColour) As 'borderColor',
CONCAT('taskcomplete.php?ex=',Excursions.idExcursions,'&id=',tasks.id) AS 'url',
CASE
WHEN Excursions.typeID = '1' THEN
date_sub(Excursions.ExcursionsStart, INTERVAL $tasks.Day_Incursion_days DAY)) As 'start',
date_sub(Excursions.ExcursionsStart, INTERVAL $tasks.Day_Incursion_days DAY)) As 'end';
SET @type = 'tasks.Day_Incursion';
WHEN '2' THEN
tasks.Overnight_Interstate,
date_sub(Excursions.ExcursionsStart, INTERVAL $tasks.Overnight_Interstate_days DAY)) As 'start',
date_sub(Excursions.ExcursionsStart, INTERVAL $tasks.Overnight_Interstate_days DAY)) As 'end';
SET @type = 'tasks.Overnight_Interstate';
WHEN '3' THEN
tasks.International,
date_sub(Excursions.ExcursionsStart, INTERVAL $tasks.tasks.International_days DAY)) As 'start',
date_sub(Excursions.ExcursionsStart, INTERVAL $tasks.tasks.International_days DAY)) As 'end';
SET @type = 'tasks.International';
END CASE;
From
tasks,
Excursions
Where
@type = 'Y' And
tasks.Sub_Task_Title = '' And
ExcursionsUser = '$_SESSION[user]'
Thank you all... so I need to:
- Split my case statements
- run a sub query to get my type of excursion and apply it to my WHERE clause
- Join my tables, thanks for pointing that out. I had forgotten
I will post an update shortly.