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 |
marcobonfante
Starting Member
1 Post |
Posted - 2014-07-04 : 05:18:24
|
Hi all guys i have this problem:i need to execute a stored procedure with a parameter on a part of the table name like this:SELECT @TSQL='SELECT dbo.ponte_codice_cassa.nome_cass , dbo.food03.id_counter , dbo.food03.data , dbo.food03.barcode , dbo.food03.descrizione , dbo.food03.codice_articolo , dbo.food03.ivathe table name food03 is the parameter i need to change but i would like thisbecause i need to recall differente table from last 2 character likefood01-->01 is the parameterfood02-->02 is the parameterfood03-->03 is the parameterdbo.food@parameter is that possible??thanksMarco |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-07-04 : 08:37:08
|
Sure. Pass the suffix as a char(2); build the query as an NVARCHAR(MAX) variable; execute the result. e.g.create proc myproc @suffix char(2)asdeclare @sql nvarchar(max) = ' select * from mytable' + @suffixexec(@sql) then run it like this:exec myproc '01' |
 |
|
|
|
|