SQL syntax help

  • I'm trying to get the following sql statement to run, but have issues with the quotations or??

    Here is the statement:

    SET @DestDB = 'FS84ZAP'                                                                       

    exec ('use ' + @DestDB + ';UPDATE PS_PV_SRCH_RUN_CTL SET FILE_DIRECTORY = ''\\serverxxx\psoft\verity\''' + @DestDB + '''')

    When I check syntax its ok.  When I click run, here is the error messge:

    Error:

    Server: Msg 170, Level 15, State 1, Line 1

    Line 1: Incorrect syntax near 'FS84ZAP'.

    Server: Msg 105, Level 15, State 1, Line 1

    Unclosed quotation mark before the character string ''.

    I've used single quotations above.  The statementwill run fine below minus the db variable:

    exec ('use ' + @DestDB + ';UPDATE PS_PV_SRCH_RUN_CTL SET FILE_DIRECTORY = ''\\serverxxx\psoft\verity\'''

     

    Appreciate help

     

  • Replace

    exec ('use ' + @DestDB + ';UPDATE PS_PV_SRCH_RUN_CTL SET FILE_DIRECTORY = ''\\serverxxx\psoft\verity\''' + @DestDB + '''')

    with

    print 'use ' + @DestDB + ';UPDATE PS_PV_SRCH_RUN_CTL SET FILE_DIRECTORY = ''\\serverxxx\psoft\verity\''' + @DestDB + ''''

    and you'll see what's wrong with the syntax of your query.

    _____________
    Code for TallyGenerator

  • Thnxs for you suggestion.  All is well.

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

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