Hi Dell,
I come back with new query, the previous setup works OK! my client would like to have more parameters:
1. Locations: either ALL or one or more;
2. time breakup: day, week, moth, quarter, year, financial year which based on
the setting Current or previous
I wonder if the following code should be set up in record selection or in the SQL command ( to integrate into the SQL)?
Could you please advise? thanks in advance.
JS
if ?location = 'ALL' then (OND.LOC = * OR L1.LNK = *)
else
if ?location IN [3,4,44,80,88, 119, 291, 292,293, 294. 295,552,553] then
join(OND.LOC = ?location) OR join(L1.LNK = ?location))
else
if ?set = 'C' then //current
if ?break = 'D' then // day
currentdate
else
if ?break = 'W' then // week
currentweek
else
if ?break = 'M' then // month
currentmonth
else
if ?break = 'Q' then //quarter
currentQuarter
else
if ?break = 'Y' then //yearly
currentyear
else
if ?break = 'F' then //financial year
the currentfinancial year // 1/7/2012 - 30/06/2013
else
if ?set = 'P' then //previous
if ?break = 'D' then // day
currentdate - 1
else
if ?break = 'W' then // week
previousweek
else
if ?break = 'M' then // month
previousmonth
else
if ?break = 'Q' then //quarter
previousQuarter
else
if ?break = 'Y' then //yearly
previousyear
else
if ?break = 'F' then //financial year
the previousfinancial year // 1/7/2011 - 30/06/2012
I could use SELECT CASE structure which is more clear.
How do I integrate 'ALL' when prompts for selecting locations:
1. All locations
2. xy
3.wu
etc
the following SQL works for one or more locations but not for 'ALL':
SELECT 'Issues' as Record_Type,
CASE WHEN LTP1.TYP = N'LINE' THEN
(CASE WHEN H1.HEAD IS NULL THEN N'None' ELSE H1.HEAD END)
ELSE
(CASE WHEN H12.HEAD IS NULL THEN N'None' ELSE H12.HEAD END)
END as Head, COUNT(*) AS Item_Count
FROM OND
INNER JOIN BFS ON OND.IRN = BFS.IRN
LEFT OUTER JOIN LOCLNK L1 ON OND.LOC = L1.IRN
LEFT OUTER JOIN LTP LTP1 ON OND.LOC = LTP1.IRN
LEFT OUTER JOIN HEADING H1 ON L1.LNK = H1.IRN
LEFT OUTER JOIN HEADING H12 ON L1.IRN = H12.IRN
WHERE LDTE BETWEEN {?start_date} AND {?end_date} AND BFS.CODE = N'IDALBY' AND( (OND.LOC IN {?location}) OR (L1.LNK IN {?location}))
GROUP BY
CASE WHEN LTP1.TYP = N'LINE' THEN
(CASE WHEN H1.HEAD IS NULL THEN N'None' ELSE H1.HEAD END)
ELSE
(CASE WHEN H12.HEAD IS NULL THEN N'None' ELSE H12.HEAD END)
END
Please advise, thanks in advance
JS
Edited by johnwsun - 25 Feb 2013 at 1:15am