Hopefully this is a quick one for someone! I’ve been searching for a while with no real answers to the question. I have a stored procedure in SQL Server 2000. I have a variable @DayToCheck which is a datetime.
@DayToCheck datetime
I need to use that for a column I am counting on. It’s not however working. I have tried converting to a varchar, but it doesn’t like that either. Here’s the two count columns I need to use.
sum(case when startdate=@DayToCheck then 1 else 0 end) as CONVERT(varchar, @DayToCheck, 103),
sum(case when startdate=DATEADD(day,-7,@DayToCheck) then 1 else 0 end) as DATEADD(day,-7,@DayToCheck)
So the above should have two columns and their alias should be the date (for column one) and -7 days off the date for column two.
Thanks for any help!
You have to use dynamic sql. So maybe something like this: