June 15, 2008 at 8:53 pm
i cant seem to figure this very simple thing out.. i have following query:
UPDATE fiscaldate
SET fiscaldateperiod = ( CASE
WHEN MONTH(fiscaldate) < 6 THEN fiscaldate+184
ELSE
fiscaldate+211
END
)
from fiscaldate
instead of adding 184 days in case the month of fiscaldate is less than june I would like to just add 6 months and instead of adding 211 days to the fiscal date in case the month is > may I would like to add 7 months. how can I do that? how do you add months to a date instead of days.
should be simple.. guess its too late for the brian the think properly... thanks
June 15, 2008 at 9:42 pm
Here you go.
UPDATE fiscaldate
SET fiscaldateperiod = ( CASE
WHEN MONTH(fiscaldate) < 6 THEN dateadd(m,6,fiscaldate)
ELSE
dateadd(m,7,fiscaldate)
END
)
from fiscaldate
June 16, 2008 at 5:37 pm
You have your answer already -- DATEADD(m,6,fiscaldate) or DATEADD(m,7,fiscaldate) -- but goodness, is my curiosity piqued.
For fiscaldate values in January through June, the result will be a date in the range July-November. For fiscaldate values in July through December, the result is in the range January-July. In other words, you never get a result in December and both December and January fiscaldates yield results in July.
Is this as you intended?
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply