Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2003
    Location
    Germany
    Posts
    17

    Unanswered: Adding a sysdate to a tablename

    Hi basically Im creating a package and I need to back up the table and put the date in the name of the table whenever the package is run, however I get an error when I try and do it, I think it should be possible but im not sure:

    SELECT *
    INTO tablename + CONVERT(char(10), GETDATE(), 112)
    FROM tablename

    So the tablename should looksomething like this

    tablename20031210

    The error message is: incorrect syntax near +

    Can anybody help.

    Thanks
    Last edited by NOODLES101487; 12-11-03 at 06:00.

  2. #2
    Join Date
    Nov 2003
    Location
    FRANCE
    Posts
    393

    Re: Adding a sysdate to a tablename

    Maybe...



    Declare @Query nVarchar(1000)

    SET @Query=N'Select * From ' + 'tablename' + CONVERT(char(10), GETDATE(), 112)

    EXECUTE sp_executesql @Query, N'@level tinyint', @level = 35

  3. #3
    Join Date
    Dec 2003
    Location
    Germany
    Posts
    17
    Thanks a lot this has been driving me crazy. I had to modify the code slightly but it works fine.

    DECLARE @Query nVarchar(1000)
    SET @Query = N'Select * INTO ' + 'tablename' + CONVERT(char(10), GETDATE(), 112) + 'FROM tablename' EXECUTE sp_executesql @Query, N'@level tinyint',
    @level = 35

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •