How do I use a variable inside of the DateDiff function?
Here's what I want to do:
SELECT *
FROM tblSchedule Sch
JOIN tlkpTimeFrame TF ON Sch.lTimeFrameID = TF.lTimeFrameID WHERE Sch.lRecur > 0
AND datediff('TF.sDatePart',Sch.dtStartTime,getDate()) % Sch.lRecur = 0
You'll notice that in parameter 1 of the DateDiff function I have placed the name of a field taken from the tlkpTimeFrame table. The sDatePart field will contain one of the datepart types (n,m,hh,yy etc).
I am trying to figure out a way to programatically generate the datepart of the DateDiff function by the sDatePart value for each record.
Here's what I want to do:
SELECT *
FROM tblSchedule Sch
JOIN tlkpTimeFrame TF ON Sch.lTimeFrameID = TF.lTimeFrameID WHERE Sch.lRecur > 0
AND datediff('TF.sDatePart',Sch.dtStartTime,getDate()) % Sch.lRecur = 0
You'll notice that in parameter 1 of the DateDiff function I have placed the name of a field taken from the tlkpTimeFrame table. The sDatePart field will contain one of the datepart types (n,m,hh,yy etc).
I am trying to figure out a way to programatically generate the datepart of the DateDiff function by the sDatePart value for each record.