Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
nokiauk
Starting Member
9 Posts |
Posted - 2012-04-03 : 06:25:26
|
Having an issue with Case & DateDiff.My line is:'VOID_DAYS2' = DATEDIFF(D,(CASE WHEN LH.ENDDATE = ISNULL THEN (LH.STARTDATE, GETDATE()) ELSE (LH.STARTDATE END) ,LH.ENDDATE),Error is:Msg 102, Level 15, State 1, Line 10Incorrect syntax near ','.Can anyone assist?Thanks |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-04-03 : 06:56:36
|
Should be more like this:SET @void_days2 = DATEDIFF( d,LH.STARTDATE, CASE WHEN LH.ENDDATE IS NULL THEN GETDATE() ELSE LH.ENDDATE END) |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2012-04-03 : 07:54:49
|
Why a CASE statement?SET @void_days2 = DATEDIFF(DAY, LH.STARTDATE, ISNULL(LH.ENDDATE, GETDATE())) N 56°04'39.26"E 12°55'05.63" |
|
|
nokiauk
Starting Member
9 Posts |
Posted - 2012-04-03 : 08:18:54
|
quote: Originally posted by SwePeso Why a CASE statement?SET @void_days2 = DATEDIFF(DAY, LH.STARTDATE, ISNULL(LH.ENDDATE, GETDATE())) N 56°04'39.26"E 12°55'05.63"
I had picked CASE as a similar report written by someone else had done it that way and a I was trying to modify that one.Your way was simpler and has worked perfectly.Many Thanks. |
|
|
|
|
|
|
|