Syntax Error...

  • This query worked fine

    select 'PRINT ''' + '---' + REPLACE(SQLNAME,'.sql','') + '''' +

    ' :r ' + @FolderName + '\' + SQLNAME

    from [dbo].[PATCHFILE]

    I store the entire query into variable @sql. Then Received syntax error msg..

    Anyone one know how to correct it ?

    SELECT @sql = 'BCP "select 'PRINT ''' + '---' + REPLACE(SQLNAME,'.sql','') + '''' +

    ' :r ' + @FolderName + '\' + SQLNAME

    from [dbo].[PATCHFILE]" queryout c:\filename.txt -c -t -U sa -P manager -S

    TCPNET\SQLEXPRESS'

  • you have to run it from cmd prompt.

    Ryan
    //All our dreams can come true, if we have the courage to pursue them//

  • I think can run on SSMS... not necessary must in cmd mood

  • declare @folderName varchar(500)

    declare @sql varchar(1000)

    set @folderName = 'Empty'

    select 'PRINT ''' + '---' + REPLACE(SQLNAME,'.sql','') + '''' +

    ' :r ' + @FolderName + '\' + SQLNAME

    from [dbo].[PATCHFILE]

    SELECT @sql = 'BCP "select ''PRINT ''' + '---' + REPLACE(SQLNAME,'.sql','') + '''' +

    ' :r ' + @FolderName + '\' + SQLNAME

    from [dbo].[PATCHFILE] --'queryout c:\filename.txt -c -t -U sa -P manager -S TCPNET\SQLEXPRESS'

    Select @sql

    Regards,
    Syed Jahanzaib Bin Hassan
    BSCS | MCTS | MCITP | OCA | OCP | OCE | SCJP | IBMCDBA

    My Blog
    www.aureus-salah.com

  • BCP is an executable, it's run from the OS command prompt, not from SSMS.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 5 posts - 1 through 4 (of 4 total)

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