sql server - SQL filter result to current month and previous two months -
here sql code:
select month = datename(month,dateadd(mm,datediff(mm,0,starttime),0)), cast ((round(((convert(decimal(10,2),sum(duration)/60)/60)),2)*55) numeric(36,2)) vexecutionglobalhistory tester <> 'dit2988' , testtypeid = 1 group dateadd(mm,datediff(mm,0,starttime),0), year(dateadd(mm,datediff(mm,0,starttime),0)) order dateadd(mm,datediff(mm,0,starttime),0), year(dateadd(mm,datediff(mm,0,starttime),0))
this query returns:
april|123 may|3456 june|856 july|345
i want return following:
may|3456 june|856 july|345
does have ideas? im using microsoft sql server management studio 2010
the following return first day of month, 2 months today:
select cast(dateadd(month, datediff(month, 0, getdate())-2, 0)as date)
so can add where
criteria:
select month = datename(month,dateadd(mm,datediff(mm,0,starttime),0)), cast ((round(((convert(decimal(10,2),sum(duration)/60)/60)),2)*55) numeric(36,2)) vexecutionglobalhistory tester <> 'dit2988' , testtypeid = 1 , starttime >= cast(dateadd(month, datediff(month, 0, getdate())-2, 0) date) group dateadd(mm,datediff(mm,0,starttime),0), year(dateadd(mm,datediff(mm,0,starttime),0)) order dateadd(mm,datediff(mm,0,starttime),0), year(dateadd(mm,datediff(mm,0,starttime),0))
Comments
Post a Comment