home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.ms-sqlserver      Notorious Rube Goldberg contraption      19,505 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 17,766 of 19,505   
   Gert-Jan Strik to dvestal@gmail.com   
   Re: Split a period of time   
   26 Feb 10 23:44:28   
   
   c29b97d5   
   From: sorrytoomuchspamalready@xs4all.nl   
      
   "dvestal@gmail.com" wrote:   
   >   
   > Suppose you were looking at widget manufacturing data, and your DB   
   > looked like this:   
   >   
   > tblWidgetsProduced   
   >   dtStartTime   
   >   dtEndTime   
   >   iWidgetsProduced   
   >   
   > Suppose you wanted to look at widgets produced per hour....but there   
   > was no guarantee that dtStartTime and dtEndTime fell on hour   
   > boundaries, so you might have the split an entry across multiple hours   
   > by allocating iWidgetsProduced proportionately across the spanned   
   > hours.  Would that be possible to do in SQL?   
      
   Please tell your trainer / professor to change the training material to   
   use proper table and column names. It is considered a bad practice to   
   prefix column names with a data type indicator. Hungarian notation for   
   table names is even worse.   
      
   To get you start: you can use DATEDIFF with the HOUR parameter to count   
   the number of hour boundaries between two datetimes. If you also have to   
   take the minutes (or seconds) count into consideration, then you might   
   need a different parameter.   
      
   Also, be aware of integer division. Make sure to cast the number of   
   Widgets Produced to a decimal if you expect the average per hour to have   
   a fraction like for example 0.5.   
      
   Good luck,   
   Gert-Jan   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca