modish
asked on
get max date record entered in previous month
Hello
I have a table where I extract data for a given day - I want to compare this data with data from previous month - but only the data for the last entry for the previous month - how would I do this?
I have a table where I extract data for a given day - I want to compare this data with data from previous month - but only the data for the last entry for the previous month - how would I do this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
yes. the dateadd(month, -1) ... will take care of any 31/30/29/28 days per month.
ASKER
Excellent and aneeshattingal solution worked as well :-)
ASKER
thanks to you both for your responses - I couldn't get aneeshattingals one to work problem with casting.- but angelIII worked brilliantly -
I changed it to be
yourfield <= dateadd(day, - datepart(day, getdate()), convert(datetime, convert(varchar(10), getdate(), 120), 120) )
to get the last day of the previous month ..
Is this the best way to do the same for the month before that.
yourfield <= dateadd(month,-1,dateadd(d