Dynamically Modify the Datepart Argument of DATEADD function in T-SQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kevinSQL
    New Member
    • Jul 2007
    • 2

    #1

    Dynamically Modify the Datepart Argument of DATEADD function in T-SQL

    Is it possible to dynamically modify the Datepart argument of the DATEADD function in T-SQL 2005.

    I am trying to do something like this but it's not happy with parameter 1:


    DECLARE @pp NCHAR(3)
    SET @pp = 'day'
    SELECT dateadd(@pp,3,' 2007-07-14 12:00:00')

    Any Ideas will be much appreciated.
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Originally posted by kevinSQL
    Is it possible to dynamically modify the Datepart argument of the DATEADD function in T-SQL 2005.

    I am trying to do something like this but it's not happy with parameter 1:


    DECLARE @pp NCHAR(3)
    SET @pp = 'day'
    SELECT dateadd(@pp,3,' 2007-07-14 12:00:00')

    Any Ideas will be much appreciated.

    put the entire select command to a variable

    Comment

    Working...