Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 urgent edit query for hourly sales and total
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

Hong Kong
165 Posts

Posted - 08/21/2014 :  13:20:22  Show Profile  Reply with Quote
How to edit this query to output the time range by hourly from 8:00 to 23:00 pm.

I hope the result is
shopid date time range trx time item amount
A shop 20140821 08:00 - 09:00 08:15 am Apple $ 50
A shop 20140821 15:00 - 16:00 15:32 pm pie $ 20
A Shop total : 70

B shop 20140821 23:00 - 24:00 23:02 pm Apple $70

Grand total : $140
SELECT CONVERT(varchar(13), xsodetail.txdate, 121) + ':00',xsodetail.dess as item, Sum(xsodetail.itemAmt) AS SalesAmount FROM xsodetail
WHERE xsodetail.txdate = Convert(varchar, GETDATE(),112)-3 and xsodetail.dess like '%[A-z]%'
GROUP BY CONVERT(varchar(13), xsodetail.txdate, 121), xsodetail.item

Yak Posting Veteran

86 Posts

Posted - 01/09/2015 :  01:02:26  Show Profile  Reply with Quote
Use Grouping Sets that will give the subtotal

Viggneshwar A
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000