August 28, 2007 at 9:59 am
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
August 28, 2007 at 10:18 am
August 28, 2007 at 10:35 am
Yes, and still not working properly, but thank you for research
August 28, 2007 at 11:32 am
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.
August 28, 2007 at 11:49 am
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