Hi All...
I'm trying to calculate a dynamic period by using a value from a table to determine the period used. i.e. in some cases I'd like to compare the dates in days and other cases in years, months etc...
DECLARE @DatePart varchar(50)
SELECT @DatePart = [DatePart] FROM tblDateParts
SELECT DateDiff (@DatePart, '2009-01-01', '2010-01-01)
In the bottom statement it fails with a "Invalid parameter 1 specified for datediff". This is because the first parameter needs to be 'wk' keyword as opposed to "wk" in a string?
I'm confused as to why the first DatePart parameter behaves this way (kinda reduces flexability I'd have thought) - does anyone know a way around this?
Many Thanks!
Rob
I'm trying to calculate a dynamic period by using a value from a table to determine the period used. i.e. in some cases I'd like to compare the dates in days and other cases in years, months etc...
DECLARE @DatePart varchar(50)
SELECT @DatePart = [DatePart] FROM tblDateParts
SELECT DateDiff (@DatePart, '2009-01-01', '2010-01-01)
In the bottom statement it fails with a "Invalid parameter 1 specified for datediff". This is because the first parameter needs to be 'wk' keyword as opposed to "wk" in a string?
I'm confused as to why the first DatePart parameter behaves this way (kinda reduces flexability I'd have thought) - does anyone know a way around this?
Many Thanks!
Rob