Am having a brain freeze…
I have 4 status dates i.e. when the status was changed on a client record and I need to then query the data and find at what status the client was at a particular date.
e.g. Data
Client Setup Date Live Date Closing Date Closed Date
0001 01/01/12 10/01/12 23/02/12 15/11/12
0002 08/10/12 11/11/12
0003 11/12/12
So for a date of 31/12/12 then 0001 would indicate a status of closed, 0002 would be Live, 0003 would be Setup.
I want to return only the Client and Status for that date.
So on 31/12/12 I would get a result of
0001 Closed
0002 Live
0003 Setup
I tried this using a case but it’s gone wrong somewhere as it seems to be returning me the same status and I can see why it doesn’t work but my little noggin can’t work out a way to get it to work. This is coming from another query that extracts and inserts into a #Temp table.
CASE
WHEN #TempOutput.[System Setup] BETWEEN @Start and @End THEN 'Prospect'
WHEN #TempOutput.[Prospect to Live] BETWEEN @Start and @End THEN 'Live'
WHEN #TempOutput.[Live to Terminal] BETWEEN @Start and @End THEN 'Terminal'
WHEN #TempOutput.Closing BETWEEN @Start and @End THEN 'Closed'
END
This is like the first step as I then need to loop through this to show what the status was of each client over a period. So if it’s a weekly period then it needs to loop through 52 times based on an entry date… I can do this bit! LOL
any help appreciated!
1 Answer