DECLARE @number int 
declare @tempsql nvarchar(8000)
declare @where   nvarchar(8000)select @tempsql=N'select @number=count(*) from product where productdwgcode = '+@code+' and ' +@whereexec sp_executesql @tempsql,N'@number int output',@number outputselect @number

解决方案 »

  1.   

    exec sp_executesql @tempsql,N'@number int output',@number output解释一下吧。n'的用法,我没用过.............先谢了
      

  2.   

    调试的时候,显示@tempsql 仍为空值呀
      

  3.   

    select @tempsql =' select count(*)  into '+ @number +' from product where productdwgcode = '+@code+' and ' +@where----
    这句的 @number +@code+@where
    有没有赋值?不然的话,这个肯定是null了
      

  4.   

    @number是要读取这个结果的, @code是有值的,不论 @number +@code+@where这三个值是否为空,至少@tempsql 里不应该为空啊