I am building a dataset to use for an ssrs parameter and I am having trouble building distinct values that result out of a case statement...i also want a comma separated array based out of result sets... small sample below..
Sample Data:
itemcode itemkey
1 1001
4 1002
5 1003
4 1004
7 1005
4 1006
8 1007
6 1008
5 1009
I do the following SELECT:
SELECT DISTINCT itemcode,
,CASE WHEN itemcode IN(1,7,8) THEN 'Green'
WHEN itemcode IN(4,5) THEN 'Red'
WHEN itemcode IN(6) THEN 'Blue'
ELSE 'itemcode'
END AS 'Color'
FROM itemtable
returns this:
itemcode Color
1 Green
4 Red
5 Red
6 Blue
7 Green
8 Green
I want to be able to SELECT DISTINCT Color (which is the case statement column) but also put the itemcodes in comma separated values.. so I would want these results (order by Color):
itemcode Color
6 Blue
1,7,8 Green
4,5 Red
this way I can use this dataset as my "Available Values" in the ssrs parameter, with Value = itemcode and Label = Color
hope this makes sense... I can clarify if needed. TIA