开发者

Stored procedure in SQL Server

开发者 https://www.devze.com 2023-03-26 23:51 出处:网络
Can I use only one stored procedure for many queries? Like this: SELECT @var开发者_C百科_name[0] from @table_name WHERE @con1 = @var_name[1] ;

Can I use only one stored procedure for many queries?

Like this:

SELECT @var开发者_C百科_name[0] from @table_name WHERE @con1 = @var_name[1] ;


You cannot do that. You could build the query dyamically with something like

EXEC('SELECT ' + @var_name + ' FROM ' + @table_name + ' WHERE ' + @Con1 + ' = ' + @var_name)

Be aware of potential performance and sql injection issues when doing this though.

0

精彩评论

暂无评论...
验证码 换一张
取 消