master..xp_cmdshell errors

  • I keep getting the error, "Incorrect syntax near '\'." and "The label 'd' has already been declared. Label names must be unique within a query batch or stored procedure."  from the master..xp_cmdshell line.  It works when I manually enter it in DOS.  Can you tell what I am doing wrong?

    CREATE              Procedure dbo.sp_ImportRawData

    (@ClientAbbrev nchar(4), @FileDate nvarchar(8), @SessionId nvarchar(50) )

    AS

    DECLARE @FullFileName nvarchar(68)

    DECLARE @sql varchar(3500)

    DECLARE @triFileName nvarchar(255)

    Declare @Ip_FileName nvarchar(255)

    Declare @Ip_Active char(1)

     

    Declare ActiveFile Cursor For

     Select Ip_FileName, Ip_Active from tbl_InputFiles

     where Ip_Active = 'Y'

    Open ActiveFile

    Fetch Next From ActiveFile

     Into @Ip_FileName, @Ip_Active

     

    While @@Fetch_Status = 0

    Begin

     Exec('truncate table tri_'+ @Ip_FileName)

     Set @FullFileName = @Ip_Filename + '.csv'

     set @triFileName = 'tri_' + @Ip_FileName

     set @sql = 'master..xp_cmdshell d:\mars_sys\common\scripts\odbcbcp -D CopyMedMgr10_Testing -i d:\mars_sys\dataupdates\ccbm\' + @FullFileName + ' -Q ' + @triFileName

    Print(@sql) 

    exec(@SQL)

    Fetch Next From ActiveFile

     Into @Ip_FileName, @Ip_Active

    End

    CLOSE ActiveFile

    DEALLOCATE ActiveFile

  • Also asked here

    http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=88529

     


    N 56°04'39.16"
    E 12°55'05.25"

  • Yes, and still not working properly, but thank you for research

  • It is working now for any of those that might run into this problem. I need to add + '''' to the end of the xp_cmdshell statement.

  • That's why you always need to PRINT the statement when using dynamic sql.

    Then you will see what is wrong.

     


    N 56°04'39.16"
    E 12°55'05.25"

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

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