@EndDate = 2010-05-31
select *
from TableName
where OrderNo = ‘AB103’
and month(SendDate) = month(dateadd(mm,-1,@EndDate))
is returning 2 values which has same month (which is April) but different years
like 2010 and 2009.
How can I change this query so that it returns value only of year 2010 and month remains April?
I have used (CONVERT(VARCHAR(6),(dateadd(mm,-1,2010-05-31)),112)+’01’)
instead for 2010-04-01
What is wrong with this code?
SendDate = (CONVERT(VARCHAR(6),(dateadd(mm,-1,2010-05-31)),112)+’01’)
I dont need value in 2010-04-01 form
I want it in this form (CONVERT(VARCHAR(6),(dateadd(mm,-1, @EndDate)),112)+’01’)
What mistake I am making?
Anyone??
You can use “between” to limit the range of dates:
Note that this assumes you are storing dates without times. It would not return a SendDate that was during the afternoon of 4/30/11.