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 |
SimonG
Starting Member
15 Posts |
Posted - 2011-05-17 : 10:07:03
|
Hi,Appreciate if someone could advise on the best way of achieving the following;I have a select query running against a table called [my company$vendor ledger entry]. I'd like to be able to specify the 'my company part as a variable so that I change the table based on the variable value.I could therefore specify 'Simon Ltd' which would run the select against [Simon Ltd$Vendor Ledger Entry] object.Is this possible?Thanks in advance.Simon |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-05-17 : 10:31:56
|
You would probably have to use dynamic sql which has security implicationsdeclare @sqlselect @sql = 'select * from [' + @myco + '$Vendor Ledger Entry]'exec (@sql)also have a look at sp_executesql==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
|
|
|