|
Question : Update/Case/add month
|
|
Hello,
This is sort of a follow up to an earlier question I had. I am updating a datetime field based on month. If the field contains a date in months 7, 8, or 9, I am adding 3 months to that date, if not then I am adding 6 months. It works just fine. Now I need a bit of help adding months to the date field not only based on the month, but also the year. I would like to add 3 months to July, August, and Sept only for the year 2007, else I want to add 6 months.
The original code is as follows:
update brfmaster set mDate = dateadd(month, case when datepart(month,mdate) in (7,8,9) then 3 else 6 end ,mDate) where editorial ='YES' and companycode='991'
The only thing missing is restricting the 3 month add to July, Aug and Sept for year 2007.
|
|
Answer : Update/Case/add month
|
|
update brfmaster set mDate = dateadd(month, case when datepart(month,mdate) in (7,8,9) and year(mdate) = 2007 then 3 else 6 end ,mDate) where editorial ='YES' and companycode='991'
|
|
|
|