sql - DateAdd with abbreviation from column -


i have have following sql increases starttime of each row in result mocktable.

select     dateadd( "d", row_number() on (order mt.id), mt.starttime ) increment     mocktable mt 

now trade "d" column specified in mocktable. this:

select     dateadd( mt.periodtime, row_number() on (order mt.id), mt.starttime ) increment     mocktable mt 

how can this? column periodtime nvarchar(5) , contain 'd', 'ww' or 'm'. reason want because user should decide incrementation of orginial date.

you can big case statement:

select (case when periodtime = 'day'              dateadd(day, row_number() on (order mt.id), mt.starttime)              when periodtime = 'month'              dateadd(month, row_number() on (order mt.id), mt.starttime)              when periodtime = 'year'              dateadd(year, row_number() on (order mt.id), mt.starttime)         end) increment mocktable mt 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -