有一个存储过程如下:
CREATE procedure Add_glb
@TableName varchar(30),
@jcmc varchar(20)
as
begin
exec('insert [' + @TableName + '](ch,zh1,jcmc,lxmc,cx,xl) select ch,zh1,jcmc,lxmc,cx,xl from chgul where [email protected]')
end
go
调用:
declare @TableName varchar(30),@jcmc varchar(20) set @TableName='F2201252' set @jcmc='_2分公司'
exec Add_glb @TableName,@jcmc
出错信息:
[email protected]
如果不加 where [email protected] [email protected]
------解决方案--------------------
- SQL code
CREATE procedure Add_glb@TableName varchar(30),@jcmc varchar(20)asbeginexec('insert [' + @TableName + '](ch,zh1,jcmc,lxmc,cx,xl) select ch,zh1,jcmc,lxmc,cx,xl from chgul where [email protected]+'''')endgo
------解决方案--------------------
exec('insert [' + @TableName + '](ch,zh1,jcmc,lxmc,cx,xl) select ch,zh1,jcmc,lxmc,cx,xl from chgul where [email protected]+'''')