日期:2014-05-17 浏览次数:20445 次
create table t1(a int) insert into t1 select 1 union select 2 declare @param nvarchar(100) declare @roadx int set @roadx = 1 set @param = '@roadx int' declare @sSql1 nvarchar(4000) declare @sSql2 nvarchar(4000) declare @sSql3 nvarchar(4000) --set @sSql1 = 'insert into t1 select * from t1 where a = @roadx ' set @sSql1 = 'insert into t1 ' set @sSql2 = ' select * from t1 where a = @roadx' set @sSql3 = @sSql1 + @sSql2 exec sp_executesql @sSql3,@param,@roadx
------解决方案--------------------
declare @param nvarchar(100) declare @roadx int set @roadx = 1 set @param = '@roadx int' declare @sSql1 varchar(4000) declare @sSql2 varchar(4000) --set @sSql1 = 'insert into t1 select * from t1 where a = @roadx ' set @sSql1 = 'insert into t1 ' set @sSql2 = ' select * from t1 where a=' exec ('declare @sSql1 varchar(4000), @sSql2 varchar(4000)'+@sSql1+@sSql2+@roadx)