ALTER procedure [dbo].[cs2]
@a nvarchar(100),
@b nvarchar(100),
@c nvarchar(100)
as
declare @d nvarchar(2000)
set @d='select * from [email protected]+' where [email protected]+' and [email protected]+''
execute sp_executesql @d
我运行exec cs2 dx,a,b
它提醒我
消息 207,级别 16,状态 1,第 1 行
列名 'a' 无效。
消息 207,级别 16,状态 1,第 1 行
列名 'b' 无效。
是哪里写错了?求说的详细点,我就是老是在这里出错
------解决方案--------------------
try this,
- SQL code
ALTER procedure [dbo].[cs2]@a nvarchar(100),@b nvarchar(100),@c nvarchar(100)asdeclare @d nvarchar(2000)set @d=N'select * from [email protected]+' where [email protected]+''' and [email protected]+''' 'execute sp_executesql @d
------解决方案--------------------
[email protected]询,[email protected], [email protected]?
建议预先建立视图将若干需要查询的表数据整合:
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 [email protected]