Need TSQL to get counts by time intervals

Last Post 13 Apr 2012 03:13 AM by Vinu Vijayan. 4 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
SQL_Jr
New Member
New Member

--
20 May 2011 06:15 AM
So, basically, have this ticketing system and need a script to return records (count) by shift.
They are 12-8, 8-4, 4-12 (8 hour shifts). Say, tickets by shift.
Need to specify date range as well.  So output should look like:

count  Shift
----------------
10      Shift1
123    Shift2
78      Shift3


TIA!
PaulMcKibben
New Member
New Member

--
20 May 2011 07:43 AM
Are you using the datetime data type for the date and time values ?
SQL_Jr
New Member
New Member

--
20 May 2011 09:55 AM

Yes, sorry forgot to mention that.  Datetime - so I guess we need to get the dateparts....

Please advise...thx

gunneyk
New Member
New Member

--
20 May 2011 02:07 PM
If you are using SQL 2008 and you want to do calculations based on the time portions you might consider creating a DATE and a TIME column instead of Datetime. Then this kind of stuff is easier. Otherwise you need to p*** out the time from the datetime and that will mean you can't use an index. It will scan the table or the entire index instead of seeking like it would if you have a TIME datatype with an index on it.
Vinu Vijayan
New Member
New Member

--
13 Apr 2012 03:13 AM
Please post your DDL and some sample data.

Vinu Vijayan
You are not authorized to post a reply.

Acceptable Use Policy