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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 bulk insert with dynamic file name?

Author  Topic 

mikejohnson
Posting Yak Master

153 Posts

Posted - 2005-01-24 : 17:29:38
this isn't working for me, what other options do i have?

--@File set already
declare @FilePath varchar(100)
set @FilePath='c:\test\' + @File
BULK INSERT TableName
FROM @FilePath --!!!!!!!ERROR ON THIS LINE!!!!!!!!!!!!!!
WITH (FieldTerminator = '',ROWTERMINATOR='{CR}{LF}')

error: Incorrect syntax near '@FilePath'.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-01-24 : 17:32:16
BULK INSERT runs from the database server and not your client machine (unless of course you are on the db server, then the client is the server also). So c:\test\FileName.txt needs to be located on the db server. You can use a share though.

[EDIT]

Oh wait! You may need dynamic SQL for this. Put the command in a variable, then EXEC (@VarName)

[/EDIT]

Tara
Go to Top of Page

mikejohnson
Posting Yak Master

153 Posts

Posted - 2005-01-24 : 17:33:56
That didn't answer my question, i already knew that. i think this will work:

declare @sql varchar(1000)
select @sql = 'bulk insert TableName FROM c:\test\' + @File
exec (@sql)
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-01-24 : 17:35:22
Did you see the EDIT in my post? I editted it right after I posted it.

Tara
Go to Top of Page
   

- Advertisement -