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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Add Decimal to DateDiff Statement

Author  Topic 

khaos
Starting Member

6 Posts

Posted - 2011-07-26 : 16:19:41
I am sure there is an easy way to do this but I cannot figure it out, I am trying to add a decimal value to a datediff statement & I still get the outcome as 0 as opposed to when I try to add a whole number such as 1 or 5, I get the desired outcome with 1 or 5 added.

Here's my code:

Select
StartDate, EndDate, CASE Type WHEN 'HALF' THEN DATEDIFF (d, StartDate, EndDate + 0.5) - (select DT from TableB)
ELSE
DateDiff (d,StartDate, EndDate + 1)
END
From Table A
Where ID=@ID AND SOLO='Complete'


The scenario with the +1 work, but where I try to add + 0.5 with the HALF scenario only returns a 0. Any ideas?

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-07-26 : 16:36:27
If you want half a day to add then take 12 hours for example.
DATEDIFF (d, StartDate, dateadd(hour,12,EndDate))


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

khaos
Starting Member

6 Posts

Posted - 2011-07-26 : 16:42:42
that didn't work, the outcome still comes as 0 wherever it is HALF
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-07-27 : 00:00:21
Do you have same sample values? Or just one example?


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -