How to get the record from table as hourly basis in SQL server? -


i have table called dailysales(id int,date date,time time,cashsale money,cardsale money,totalsale money).now want below result...

                  date : 04-06-2015                    time : 09:01 - 10:00 cashsale           cardsale                   totalsale 10000.00           15000.00                   25000.00                   time : 10:01 - 11:00 cashsale           cardsale                   totalsale 20000.00           15000.00                   35000.00 . . . 

please me, thanks..

i'd suggest best bet store date/time in datetime or datetime2 column rather storing time, use can use datepart function hour.

assuming time column datetime, like:

select date,         datepart(hour, time) hour,         sum(cashsale) bycash,         sum(cardsale) bycard,         sum(totalsale) netsale   dailysales group date, datepart(hour, time) 

this split hour hour, on hour (e.g 09:00:00 09:59:59, 10:00:00 10:59:59, etc.). if wanted offset split takes place, example @ 1 minute past hour, can use dateadd function, example dateadd(minute, -1, time), in place of time.

if you're storing string in other way, example string, you'd want group string expression based on that, e.g. left(time, 2)


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -