DateAdd Help....Using a variable for datepart

  • hey all-

    I cannot figure out how to us a variable for the datepart of DateAdd function.

    Example...

    declare @datepart char(5)

    SELECT @datepart = 'day'

    select due_Date, time_span,

    (dateadd(@datepart,10,due_date)) as plus10

    from schedule

    Anyone ever done this before? Any help would be great!

    Thanks,

    Doug

  • Sorry the function deveopers in SQL did not leave a way for this to be done in SQL with dateadd. The only was is to build the SQL string dynamically like so:

    declare @datepart char(5)

    SELECT @datepart = 'day'

    EXEC ('select due_Date, time_span,

    (dateadd(' + @datepart + ',10,due_date)) as plus10

    from schedule')

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply