August 5, 2009 at 9:49 pm
We have database called store, I have an issue to generate the hourly count report dynamically.
Whenever I execute the below query and I get the output as below
Date_Time MsgCount
2009-08-06 01 2452
2009-08-06 02 2210
2009-08-06 03 4173
2009-08-06 04 6450
2009-08-06 05 5452
2009-08-06 06 2452
2009-08-06 07 2462
2009-08-06 10 4521
But I need the output should be
Date_Time MsgCount
2009-08-06 01 2452
2009-08-06 02 2210
2009-08-06 03 4173
2009-08-06 04 6450
2009-08-06 05 5452
2009-08-06 06 2452
2009-08-06 07 2462
2009-08-06 08 0
2009-08-06 09 0
2009-08-06 10 4521
I am using the query to generate the report as below,
select convert(varchar(13), lastupdated, 120) As Date_Time, count(*) As MsgCount from store_details(nolock)
group by convert(varchar(13), lastupdated, 120)
order by convert(varchar(13), lastupdated, 120)
Please help me how will I get the output.
Thanks in Advance
August 5, 2009 at 10:39 pm
Heh... get busy Karthik... you know how to use a Tally table with an outer join. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
August 5, 2009 at 10:50 pm
AND you've been around long enough to know how to post data to get help. If not, please reread the article at the first link in my signature below. I'm going to stop helping unless you start helping. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
August 5, 2009 at 11:29 pm
AND you posted this on both the 2k and 2k5 forum! You know better than to double post! All it does is tick people off. Stop it. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
August 5, 2009 at 11:33 pm
August 6, 2009 at 12:08 am
karthikeyan (8/5/2009)
My requirement is different.
Not according to what you posted. Capture the output in a temp table and apply a Tally table to get the dates.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 6, 2009 at 11:53 am
Quick question... are you the same Karthikeyan that is a "Senior Software Engineer" working on a PHD or are you someone else?
--Jeff Moden
Change is inevitable... Change for the better is not.
August 7, 2009 at 5:02 am
August 7, 2009 at 6:42 am
Ah... my very bad then... you are a different Karthik than the one I'm used to working with. Someone showed me that there are two people with the same "Karthikeyan" handle on this forum and I didn't know that was possible. The one I've worked with in the past knows all about the Tally table. My most humble apologies for the confusion.
I'm on my way to work... I'll try to bang this out during lunch unless someone beats me to it.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply