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 2008 Forums
 Transact-SQL (2008)
 Using Datepart getting hour info

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2013-05-02 : 07:28:45
Is there a better way to get the hour information, or is this the most optimized mode, please need help



CASE
WHEN DATEPART(Hour, StartDTM) = 1 THEN
CASE
WHEN DATEPART(Hour, EndDTM) = 1 THEN
CAST(DATEPART(minute, EndDTM) - DATEPART(minute, StartDTM) AS FLOAT)/60
ELSE
CAST(60 - DATEPART(minute, StartDTM) AS FLOAT)/60
END
WHEN DATEPART(Hour, EndDTM) = 1 THEN
CAST(DATEPART(minute, EndDTM) AS FLOAT)/60
WHEN 1 BETWEEN DATEPART(Hour, StartDTM) AND DATEPART(Hour, EndDTM) THEN 1
ELSE 0
END AS '1AM',


Thank you very much for the helpful info.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-05-02 : 07:37:33
can you explain in words what you're trying to achieve?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -