Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
mwendel2
Starting Member
3 Posts |
Posted - 2010-05-17 : 15:04:11
|
| I have been reading on this all day and it would appear that when I do @pathfile in the FROM portion of the BULK INSERT statement the entire file's contents are pulling into @pathfile?Is this correct? (see query below) If yes, is there a way to make what I am doing work as just a passed file name? If not, any suggestions as to why the query is returning:Msg 4860, Level 16, State 1, Line 8Cannot bulk load. The file "@pathfile" does not exist.DECLARE @counter IntDECLARE @pathfile varchar(500)SET @counter = 3WHILE @counter < 32BEGIN SET @pathfile = 'C:\clientname\OrderReport\Processed\2009-09\OrderSummary_2009090' + RTRIM(CAST(@counter AS CHAR)) + '.txt' PRINT 'The file is ' + @pathfile BULK INSERT clientname.dbo.OrderSummary FROM '@pathfile' WITH ( FIRSTROW = 2, BATCHSIZE = 1, MAXERRORS = 100, FIELDTERMINATOR = '\t', ROWTERMINATOR = '\n' ) SET @counter = @counter + 1ENDGOThanks in advance for any assistance. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
mwendel2
Starting Member
3 Posts |
Posted - 2010-05-17 : 15:16:19
|
| I am running everything locally on my laptop.When I removed the quotes around @pathfile, I then get:Msg 102, Level 15, State 1, Line 9Incorrect syntax near '@pathfile'.Msg 319, Level 15, State 1, Line 10Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
mwendel2
Starting Member
3 Posts |
Posted - 2010-05-18 : 09:47:26
|
| Thank you. That worked. Now I have to deal with other issues as a result of getting past that point. :) |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|
|