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
 General SQL Server Forums
 New to SQL Server Programming
 Use of variable in openrowset bulk statement

Author  Topic 

dariopalermo
Starting Member

16 Posts

Posted - 2011-06-04 : 17:48:26
This:


set @fmtfile='''\\mu\ftptimb\eav\' + @azienda + '.fmt'''
set @timbfile='''\\mu\ftptimb\eav\' + @azienda + '\archivio\timb.txt'''
select * from OPENROWSET( BULK @timbfile, FORMATFILE = @fmtfile) AS timb;


isn't working, while this:


select * from OPENROWSET( BULK '\\mu\ftptimb\eav\' + @azienda + '\archivio\timb.txt', FORMATFILE = '\\mu\ftptimb\eav\' + @azienda + '.fmt') AS timb;


works. I also tried with single ' instead of triple ''' in the set statements.

How can I fix it?

Thanks,

Dario

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-06-05 : 03:34:47
you need to use dynamic sql for this

http://community.sgdotnet.org/blogs/chuawenching/archive/2006/04/03/25601.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dariopalermo
Starting Member

16 Posts

Posted - 2011-06-06 : 03:47:28
Thanks visakh16, it solved my problem.

Bye,

Dario
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-06-12 : 04:50:25
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -