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
 General SQL Server Forums
 New to SQL Server Programming
 Hourly breakdown

Author  Topic 

hayko98
Starting Member

29 Posts

Posted - 2011-06-23 : 20:33:34
Hi all,
I am running query that breaks (groups) results down of each hour interval.
SELECT datepart(hh,due_time ),due_time
FROM someTable
ORDER BY 1
HrBucket due_time
3 2011-03-31 03:26:49.593
3 2011-03-31 03:26:49.593
5 2011-03-30 05:59:56.503
5 2011-03-30 05:59:52.747
5 2011-03-28 05:59:47.713
5 2011-03-27 05:59:13.717
6 2011-03-27 06:02:31.720
6 2011-03-27 06:02:56.437
As You can see there is nothing for HrBucket ‘4’.I need to have all HrBuckets with or without data. Is it possible?

Thank you

jfarrugia
Yak Posting Veteran

55 Posts

Posted - 2011-06-24 : 06:12:59
you could create a temp table with one column for all hours.. and create an outer join. Display ALL hours from the temp table.. that will give u due_time as NULL when HRBucket is 4

Where software development knowledge meets the reader
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-06-25 : 14:03:04
another way is to use a tally table to generate hour values and use it for left joining to your table.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -