大家可能碰到这样的情况
@condition 是外部传入的条件
DECLARE @strsql varchar(3000)
declare @icount int
begin
set @strsql ='SELECT @icount=count(*) from table' + @condition
end
如果你写 exec @strsql,虽然编译不会错误,但是输出结果是错的
正确写法:exec (@strsql ) --记得要带括号()
大家可能碰到这样的情况
@condition 是外部传入的条件
DECLARE @strsql varchar(3000)
declare @icount int
begin
set @strsql ='SELECT @icount=count(*) from table' + @condition
end
如果你写 exec @strsql,虽然编译不会错误,但是输出结果是错的
正确写法:exec (@strsql ) --记得要带括号()