Results 1 to 3 of 3

Thread: Executing SQL statements through variables

  1. #1
    Join Date
    Sep 2002
    Location
    Berkshire
    Posts
    23

    Executing SQL statements through variables

    Hi,

    I try to run sql statement by placing them in a variable as given below but receive the following error message

    set @sql_string= 'BACKUP DATABASE '+ @temp_db+' TO '+ @bk_device+' WITH FORMAT,INIT, NAME = '''+ @bk_name+''''
    EXECUTE IMMEDIATE @sql_string


    Error Message

    Server: Msg 2812, Level 16, State 62, Line 10
    Could not find stored procedure 'IMMEDIATE'.
    Server: Msg 2812, Level 16, State 62, Line 18
    Could not find stored procedure 'BACKUP DATABASE DTSTEST TO bk_dev1 WITH FORMAT,INIT, NAME = 'Full backup''.


    Thanks
    John Jayaseelan

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    Try 'exec (@sql_string)'.

  3. #3
    Join Date
    Sep 2002
    Location
    Berkshire
    Posts
    23
    It worked. Thanks

Posting Permissions

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