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 |
|
Sean_B
Posting Yak Master
111 Posts |
Posted - 2007-05-01 : 05:20:35
|
| Hi,Can anyone help.I'm trying to populate a variable (@FileDate) in a stored procedure via a piece of dynamic sql (see below).Unfortunately this doesn't seem to work. Is there a way around this ?SET @SQL = 'select @FileDate = t1.FileDate ' + char(10)SET @SQL = @SQL + 'FROM OPENROWSET (BULK' + char(10)SET @SQL = @SQL + ' ''' + @DataFileFilePath + @FileName + ''',' + char(10)SET @SQL = @SQL + ' LASTROW=1,' + char(10)SET @SQL = @SQL + ' FORMATFILE=''' + @FormatFilePath + 'tempibesdate.xml'') AS t1' + char(10)Sean |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-05-01 : 05:28:00
|
are you using exec() ? You should be using sp_executesql KH |
 |
|
|
Sean_B
Posting Yak Master
111 Posts |
Posted - 2007-05-01 : 05:51:08
|
| Yes, I was using exec, I've changed it to sp_executesql and it now works, thank you.Sean |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-05-05 : 04:27:27
|
| More on dynamic sqlwww.sommarskog.se/dynamic_sql.htmlMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|