In need to create an IN clause with a list of dates in it. The list needs to be in descending order. I created a variable named @cols and am trying to populate it with this code:
declare @end date='2016/05/30'
declare @begin date = DATEADD(month, DATEDIFF(month, 0, @end), 0) ;
declare @curdate date = @end; -- start on the last day
print @curdate;
print @begin;
DECLARE @cols NVARCHAR (MAX)
while @curdate >=@begin -- goes from end of the month to beginning of the month
begin
select @cols = @cols + ',[' + CONVERT(NVARCHAR, @curdate, 106) + ']';
select @curdate = DATEADD(DAY,-1,@curdate ) -- subtract a day
end
print @cols;
print @curdate;
print @begin;
I'm hoping to get 5/30/16, 5/29/16, 5/28/16 etc (properly formatted of course). The code runs without error however @cols is always empty.