Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all,


i am using sql express, I have table where all the entries are going, now i want the report to be generated from this table.

it should show like this:
Time no of sales TotalAmount
9:00 - 10:00 2 1300
10:00 - 11:00 4 1500
11:00 - 12:00 9 3500

AND SO ON..

Please tell me how to do it.

Thanks & Regards,
Mohi
Posted
Comments
ssd_coolguy 26-Jun-12 7:02am    
hi..
is your table contains only 1 day data?

1 solution

i think this link will help you

http://blog.sqlauthority.com/2009/08/06/sql-server-get-time-in-hourminute-format-from-a-datetime-get-date-part-only-from-datetime/[^]
and
http://www.sqlusa.com/bestpractices2005/centurydateformat/[^]

use case, datepart, group by statement to calculate no. of sales & TotalAmount.

SQL
Select cast(DATEPART(HH, Time) as varchar(10))+ ':00', COUNT(1), SUM(Amount) from DemoTable group by DATEPART(HH, Time)


please check the above query this will help you to write your query
 
Share this answer
 
v3
Comments
mvengaqua 26-Jun-12 7:24am    
thanks Irfan

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900