sql server 2008 r2 - How to get records of last month of this year, -
i need fetch records of last month of year, getting records of past years also. please me out
i had query this:
select empcode,eventdate1 eventdate,intime, case when outtime null 'n/a' else outtime end outtime tms_hourcalc datepart(m, eventdate) = datepart(m, dateadd(m, -1, getdate())) , empcode='13658' group empcode, intime,outtime, eventdate1,intime1 order intime1;
you need check year condition well.
select empcode,eventdate1 eventdate,intime, case when outtime null 'n/a' else outtime end outtime tms_hourcalc datepart(m, eventdate) = datepart(m, dateadd(m, -1, getdate())) , datepart(y, eventdate) = datepart(y, dateadd(m, -1, getdate())) , empcode='13658' group empcode, intime,outtime, eventdate1,intime1 order intime1;
Comments
Post a Comment