日期:2014-05-18 浏览次数:20538 次
Create procedure AddDataDB @strTable varchar(200), @strColl varchar(4000), @strValue ntext, @strWhere varchar(4000)='' as begin if ISNULL(@strWhere,'')='' set @strWhere='' else set @strWhere='where'+@strWhere exec('insert into'+@strtable+N'('+@strColl+N')values('+@strValue+N')'+@strWhere) end
create proc TestSP as begin declare @strTable varchar(200),@strColl varchar(4000),@strValue ntext,@strWhere varchar(4000) declare @sql nvarchar(2000) set @strWhere='' if ISNULL(@strWhere,'')='' set @strWhere='' else set @strWhere='where'+@strWhere set @sql='insert into'+@strtable+N'('+@strColl+N')values('+@strValue+N')'+@strWhere execute sp_executesql @sql,N'@strtable varchar(200),@strColl varchar(4000),@strValue ntext,@strWhere varchar(4000)' , @strTable ,@strColl ,@strValue ,@strWhere end
create proc TestSP as begin declare @strTable varchar(200),@strColl varchar(4000),@strValue ntext,@strWhere nvarchar(4000) declare @sql nvarchar(2000) set @strWhere='' if ISNULL(@strWhere,'')='' set @strWhere='' else set @strWhere=N'where'+@strWhere set @sql=N'insert into'+@strtable+N'('+@strColl+')values('+@strValue+')'+@strWhere execute sp_executesql @sql,N'@strtable varchar(200),@strColl varchar(4000),@strValue ntext,@strWhere nvarchar(4000)' , @strTable ,@strColl ,@strValue ,@strWhere end
------解决方案--------------------
A. 执行简单的 SELECT 语句 下面的示例创建并执行一个简单的 SELECT 语句,其中包含名为 @level 的嵌入参数。 execute sp_executesql N'select * from pubs.dbo.employee where job_lvl = @level', N'@level tinyint', @level = 35