December 3, 2009 at 6:09 pm
I want to write a bulk insert statement that utilizes a variable:
Bulk Insert #TABLE
FROM @SOURCE
WITH (ROWTERMINATOR = '')
I know the common way to do this is to use the EXEC command, which I wrote as:
SET @RUNNER =
'Bulk Insert #TABLE
FROM' + @SOURCE +
'WITH (ROWTERMINATOR = '''')'
EXEC(@RUNNER)
However, I'm getting a consistent error around the rowterminator. The EXEC command doesn't seem to like it, and my attempts to reformat it have failed.
Is there a way to use a variable and this row terminator?
December 4, 2009 at 3:09 am
Don't forget to add the necessary blanks around FROM and WITH:
ET @RUNNER =
'Bulk Insert #Table
FROM ' + @SOURCE +
' WITH (ROWTERMINATOR = '''')'
For the row terminator - see BOL--->Specifying Field and Row Terminators.
December 4, 2009 at 6:48 am
This shouldn't give any erros. you can use this
BULK INSERT <Table Name>
FROM <File Location> (Full path)
WITH
(
FIELDTERMINATOR ='|',
ROWTERMINATOR = ''
)
December 4, 2009 at 11:31 am
dmoldovan (12/4/2009)
Don't forget to add the necessary blanks around FROM and WITH:ET @RUNNER =
'Bulk Insert #Table
FROM ' + @SOURCE +
' WITH (ROWTERMINATOR = '''')'
For the row terminator - see BOL--->Specifying Field and Row Terminators.
Still getting errors on this one.
One thing I am doing is using a UNC path for my filepath. Aka \\server\xxxxx
Bulk Insert has never had a problem with it, is there an issue when used in an EXEC statement?
December 4, 2009 at 12:27 pm
Can you post the error message?
December 4, 2009 at 12:40 pm
dmoldovan (12/4/2009)
Can you post the error message?
MSG 102, LEVEL 15, STATE 1, Line 1
Incorrect syntax near '\'.
I should mention I have also tried escape all the slashes with [] and '' but neither seemed to work.
December 4, 2009 at 12:50 pm
I FIGURED IT OUT!
The problem wasn't the slashes....the problem was a bulk insert statement requires its path put in quotes.
when I did this (set @var = '\\stuff')....I was providing the command \\stuff......not '\\stuff'.
Once I changed it to set @var = '''\\stuff''' it worked like a charm.
Thanks for everyone's help, this one was maddening.
December 4, 2009 at 12:55 pm
Try something like
SET @source = '''\\server\xxxxx'''
December 4, 2009 at 12:59 pm
i got your problem....The server should be FTP and Folder should be shared...
If you get a chance place the error message..it would helpful to debug...
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply