Declare @schDatePart nvarchar(4)
Set @schDatePart = " "
Select @schDatePart = Sch.sDatePart
FROM tblSchedule Sch
Where Sch.lRecur > 0 AND datediff(@schDatePart,Sch.dtStartTime,getDate()) % Sch.lRecur = 0
In the above query, I am attempting to use the value from the tblSchedule sDatePart field to fill in parameter 1 of the dateDiff() function.
As you can see, I declared a variable named @schDatePart, then I set the variable in the select statement. The Sch.sDatePart values are either d,wk,mm or yy.
When I run the query, SQLServer gives me the following error: Invalid parameter 1 specified for datediff.
I have confirmed that the values in the Sch.sDatePart do not have trialing whitespaces or the like.
I'm thinking that I'm going about this the wrong way - any tips on this?
Set @schDatePart = " "
Select @schDatePart = Sch.sDatePart
FROM tblSchedule Sch
Where Sch.lRecur > 0 AND datediff(@schDatePart,Sch.dtStartTime,getDate()) % Sch.lRecur = 0
In the above query, I am attempting to use the value from the tblSchedule sDatePart field to fill in parameter 1 of the dateDiff() function.
As you can see, I declared a variable named @schDatePart, then I set the variable in the select statement. The Sch.sDatePart values are either d,wk,mm or yy.
When I run the query, SQLServer gives me the following error: Invalid parameter 1 specified for datediff.
I have confirmed that the values in the Sch.sDatePart do not have trialing whitespaces or the like.
I'm thinking that I'm going about this the wrong way - any tips on this?