Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calc Time query
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Miscellaneous
Thread ID:
00594564
Message ID:
00594645
Views:
24
Try
 Select mb.blockid
      SUM( DATEDIFF( mi, mb.BEGINTIME, mb.ENDTIME)) AS blocktime, 
      SUM( DATEDIFF( mi, ap.BEGINTIME, ap.ENDTIME)) AS usedtime,
      SUM( DATEDIFF( mi, ap.BEGINTIME, ap.ENDTIME)) /
        SUM( DATEDIFF( mi, mb.BEGINTIME, mb.ENDTIME)) AS used, 
  FROM  meetings mb 
  JOIN  meetings ap ON mb.BLOCKID = ap.BLOCKID 
    AND mb.ISBLOCK = 1 AND ap.BLOCKMEMBER = 1
  GROUP BY mb.blockid
>I have a table called meetings with the following:
>
>
>MEETINGID BEGINTIME           ENDTIME           ISBLOCK  BLOCKID BLOCKMEMBER
>INT          DT                 DT               BIT      INT      BIT
>------------------------------------------------------------------------
>1         12/14/2001 07:00   12/14/2001 12:00     1        1        0
>2         12/14/2001 07:00   12/14/2001 08:00     0        1        1
>3         12/14/2001 08:15   12/14/2001 09:45     0        1        1
>
>
>I need to create a sp that returns the percent of time used for a given blockID.
>In the example above, the first record represents the block itself and the total available for the block (ISBLOCK is the flag). The second and third record represent appts scheduled within the block (Represented by BLOCKMEMBER) and tied to the block by BlockID
>
>In the above case I know that I have 5 hours of which 1.5 hours are used so I want to return .30 as used.
>
>I'm hoping someone can give me a pointer how how to structure the SQL command.
>
>Thanks in advance
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform