怎么就没人回答这个问题呢?select @totalrec=count(*) from spzs where datediff(day,idate,getdate()) <= @tl @sql 其中@sql是一个条件字符串,现在怎么能把他们连起来?现在提示语法错误!!

解决方案 »

  1.   

    @tl @sql !这怎么可能啊!我没有见过!
      

  2.   

    @sql里面是个字符串,是另外的条件,比如@sql=“and 1=1”现在要连接上,可以总报语法错误,我还不想用SQL=‘select @totalrec=count(*) from spzs where datediff(day,idate,getdate()) <= @tl’+@sql
    exec(@sql)的形式,就想直接用select @totalrec=count(*) from spzs where datediff(day,idate,getdate()) <= @tl +@sql
    明白吗?
      

  3.   

    好像做不到吧!
    如你所说的:
    set @sql=N'select @totalrec=count(*) from spzs where datediff(day,idate,getdate()) <= @tl'+@sql
    exec(@sql)
    --也不会得到正确结果的。
    而应该是:
    set @sql='select @totalrec=count(*) from spzs where datediff(day,idate,getdate()) <= '+@tl+@sql
    EXECUTE sp_executesql @SQL,N'@totalrec int output',@count output
      

  4.   

    楼上的能解释一下最后这句是什么意思吗?@count output又代表什么?