sql server - How to get data from date 15th to 15th -
i have table of user's input times follows :
table name timebilling :
fields :
timebillingid int userid int starttime datetime stoptime datetime elapsedtime time(7) normaltime time(7) overtime time(7)
now want report in want calculate total times of users. total elapsedtime, total normaltime , total overtime month.
but month 15th 15th. want results should :
user month totaltime normaltime overtime 1 march-april 120:58:00 100:58:00 20:00:00 2 march-april 97:40:23 97:40:23 00:00:00 1 april-may 15:00:00 14:30:00 00:30:00 2 april-may 89:30:00 80:15:00 09:15:00
i using query working month month :
select month(tym.stoptime) month, year(tym.stoptime) year, u.userid, isnull((select cast(sum(datediff(second,0,t.elapsedtime))/3600 varchar(20)) + ':' + right('0' + cast(sum(datediff(second,0,t.elapsedtime))/60%60 varchar(20)),2) + ':' + right('0' + cast(sum(datediff(second,0,t.elapsedtime))%60 varchar(20)),2) timebilling t month(t.stoptime) = month(tym.stoptime) , year(t.stoptime) = year(tym.stoptime) , t.userid = u.userid),'00:00:00') totaltime, isnull((select cast(sum(datediff(second,0,t.normaltime))/3600 varchar(20)) + ':' + right('0' + cast(sum(datediff(second,0,t.normaltime))/60%60 varchar(20)),2) + ':' + right('0' + cast(sum(datediff(second,0,t.normaltime))%60 varchar(20)),2) timebilling t month(t.stoptime) = month(tym.stoptime) , year(t.stoptime) = year(tym.stoptime) , t.userid = u.userid),'00:00:00') normaltime, isnull((select cast(sum(datediff(second,0,t.overtime))/3600 varchar(20)) + ':' + right('0' + cast(sum(datediff(second,0,t.overtime))/60%60 varchar(20)),2) + ':' + right('0' + cast(sum(datediff(second,0,t.overtime))%60 varchar(20)),2) timebilling t month(t.stoptime) = month(tym.stoptime) , year(t.stoptime) = year(tym.stoptime) , t.userid = u.userid),'00:00:00') overtime timebilling tym, users u tym.userid = u.userid
i got totaltime month month 1st 30th/31st. want 15th 15th. don't know how in sql query or stored procedure.
can me please ?
select userid, month, sum(...) totaltime, sum(...) totalnormaltime.... ( select t.*, case when day(starttime) > 15 datename(month, starttime) + '-' + datename(month, dateadd(month, 1, starttime)) else datename(month, dateadd(month, -1, starttime)) + '-' + datename(month, starttime) end month timebilling t ) tx group userid, month
Comments
Post a Comment