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.
Author |
Topic |
usafelix
Posting Yak Master
165 Posts |
Posted - 2014-09-03 : 01:19:53
|
if now the system time is 2014-12-23 23:45:345 . then I want to calculate the sales amount with total and get current date and current hour filter by hh:00-hh:59 , my desire output is like below :Current time:23:50 run this queryDate Time amount2014-12-23 23:40 $102014-12-23 23:01 $52014-12-23 23:39 $5Total :$20 Anyone can help write this query ? |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2014-09-03 : 04:42:13
|
[code]SELECT [date] = dateadd(day, datediff(day, 0, createdatetime), 0), [time] = convert(varchar(5), createdatetime, 108), [amount] = sum(actualsalesamt)FROM xsodetailWHERE createdatetime >= dateadd(hour, datediff(hour, 0, getdate()), 0),AND createdatetime >= dateadd(hour, datediff(hour, 0, getdate()) + 1, 0)GROUP BY dateadd(day, datediff(day, 0, createdatetime), 0), convert(varchar(5), createdatetime, 108)[/code] KH[spoiler]Time is always against us[/spoiler] |
|
|
|
|
|
|
|