Here is the code:
declare
@allcounterids varchar(max),
@counteridquery varchar(max);
select
@allcounterids = stuff((
select
'],[' + cast([CounterId] as varchar(32))
from
AllCounters
WHERE DateTime > '2011-08-15' and DateTime < '2011-08-19' and [Type] = 1
for xml path('')), 1, 2, '') + ']';
Select statement
SELECT [Type], [DateTime], Value, AllCounters.CounterId
FROM AllCounters
WHERE CounterId IN @allcounterids
as you can see i have created the varialble '@allcounterids' and populated data in it, my question is can I use this variable in where clause of Select?