April 13, 2009 at 5:03 am
Hi Masters,
I have the folowing t-sql , and get the folowing error. Can someone help please?
Tks,
Pedro
exec('create proc BULK_INSERT_DATA(@caminho varchar(500))
as
set xact_abort on
set nocount on
declare @SQLStatement as varchar(500)
truncate table bulk_Contribuintesest
set @SQLStatement=(''BULK INSERT bulk_Contribuintesest
FROM ''''+@caminho+''\ContribuintesTipo21.txt''
WITH
(
FIRSTROW =2,
FIELDTERMINATOR =''|'',
ROWTERMINATOR ='''',
tablock,
DATAFILETYPE =''widechar''
)'')
exec (@SQLStatement)
error generated by query analiser:
Line 26: Incorrect syntax near '\'.
Server: Msg 170, Level 15, State 1, Procedure BULK_INSERT_DATA, Line 42
Line 42: Incorrect syntax near '\'.
Server: Msg 170, Level 15, State 1, Procedure BULK_INSERT_DATA, Line 58
Line 58: Incorrect syntax near '\'.
Server: Msg 170, Level 15, State 1, Procedure BULK_INSERT_DATA, Line 73
Line 73: Incorrect syntax near '\'.
Server: Msg 170, Level 15, State 1, Procedure BULK_INSERT_DATA, Line 88
Line 88: Incorrect syntax near '\'.
Server: Msg 170, Level 15, State 1, Procedure BULK_INSERT_DATA, Line 103
Line 103: Incorrect syntax near '\'.
Server: Msg 170, Level 15, State 1, Procedure BULK_INSERT_DATA, Line 117
Line 117: Incorrect syntax near '\'.
Server: Msg 170, Level 15, State 1, Procedure BULK_INSERT_DATA, Line 132
Line 132: Incorrect syntax near '\'.
Server: Msg 170, Level 15, State 1, Procedure BULK_INSERT_DATA, Line 147
Line 147: Incorrect syntax near '\'.
Server: Msg 170, Level 15, State 1, Procedure BULK_INSERT_DATA, Line 162
Line 162: Incorrect syntax near '\'.
Server: Msg 170, Level 15, State 1, Procedure BULK_INSERT_DATA, Line 177
Line 177: Incorrect syntax near '\'.
Server: Msg 170, Level 15, State 1, Procedure BULK_INSERT_DATA, Line 193
Line 193: Incorrect syntax near '\'.
Server: Msg 170, Level 15, State 1, Procedure BULK_INSERT_DATA, Line 208
April 13, 2009 at 1:00 pm
It is an issue with quotes .. try
EXEC ('create proc BULK_INSERT_DATA ( @caminho varchar(500) )
as
set xact_abort on
set nocount on
declare @SQLStatement as varchar(500)
truncate table bulk_Contribuintesest
set @SQLStatement = ( ''BULK INSERT bulk_Contribuintesest
FROM '''''' + @caminho + ''\ContribuintesTipo21.txt''''
WITH (FIRSTROW =2,
FIELDTERMINATOR =''''|'''',
ROWTERMINATOR ='''''''',
tablock,
DATAFILETYPE =''''widechar''''
EXEC @SQLStatement')
I am a bit confuse on why are you doing it this way? Why not just create the stored procedure?
Thanks.
Mohit K. Gupta, MCITP: Database Administrator (2005), My Blog, Twitter: @SQLCAN[/url].
Microsoft FTE - SQL Server PFE
* Some time its the search that counts, not the finding...
* I didn't think so, but if I was wrong, I was wrong. I'd rather do something, and make a mistake than be frightened and be doing nothing. :smooooth:[/font]
April 13, 2009 at 1:39 pm
If you are trying to do this from some application, you could just run a .sql script with the proc code.
If you are building the proc dynamically, why?
Follow me on Twitter: http://www.twitter.com/way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply