日期:2014-05-18 浏览次数:20530 次
ALTER procedure [dbo].[cs2] @a nvarchar(100), @b nvarchar(100), @c nvarchar(100) as declare @d nvarchar(2000) set @d=N'select * from '+'i_'+@a+' where iname='''+@b+''' and ipassword='''+@c+''' ' execute sp_executesql @d
------解决方案--------------------
似乎是要从若干个表中按参数@a选择某个表进行查询,条件为iname=@b, ipassword=@c?
建议预先建立视图将若干需要查询的表数据整合:
create view vw_tb_name_passwd as
select tbname='tb_a', iname=iname, ipassword=ipassword
from tb_a
union
select tbname='tb_b', iname=iname, ipassword=ipassword
from tb_b
..
然后基于此视图进行查询:
ALTER procedure [dbo].[cs2]
@a nvarchar(100),
@b nvarchar(100),
@c nvarchar(100)
as
select *
from vw_tb_name_passwd
where 1=1
and tbname = @a
and iname = @b
and ipassword=@c