Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Variable File Names

Status
Not open for further replies.

FaStOnE

Programmer
Jan 4, 2002
14
US
How do I use a Variable File Name to do (in this instance) a Bulk Insert from?

**Sample Code**

Declare @Server VarChar( 50)
Declare @Path VarChar(150)
Declare @File VarChar( 50)
Declare @Ext VarChar( 5)

Set @FName = @Server + @Path + @File + @Ext
Bulk Insert db..Table01 From @Fname

Table Table01 is defined as One Column with Varchar(2000)

I get syntax errors on the Bulk Insert Statement.

Any suggestions??

Rick
 
Use dynamic SQL. The basic syntax is ...

Declare @Server VarChar( 50)
Declare @Path VarChar(150)
Declare @File VarChar( 50)
Declare @Ext VarChar( 5)
Declare @sql varchar(400)

Set @FName = @Server + @Path + @File + @Ext
Set @sql='Bulk Insert db..Table01 From ' + @Fname
Exec(@sql)
Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top