SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Using Datepart getting hour info
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

cplusplus
Aged Yak Warrior

541 Posts

Posted - 05/02/2013 :  07:28:45  Show Profile  Reply with Quote
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.

Edited by - cplusplus on 05/02/2013 07:30:47

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 05/02/2013 :  07:37:33  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.2 seconds. Powered By: Snitz Forums 2000