declare @int_count int
declare @nvar_sql nvarchar(2000)
set @nvar_sql='select ''@int_count''=count(*) from AUTHORS'  
exec sp_executesql @nvar_sql

解决方案 »

  1.   

    把变量@int_count用两个单引号加起来,放在@nvar_sql的选择语句中!
      

  2.   

    DigJim(挖土) :你的方法我试过,但是我用print @int_count出来的值还是空啊
      

  3.   

    declare @int_count int
    declare @nvar_sql nvarchar(2000)
    set @nvar_sql='select @a=count(*) from testtbl'  /*(这里的SQL语句实际上应该是动态的,这里是为了简便)*/
    exec sp_executesql @nvar_sql,N'@a int output',@int_count output
    select @int_count
      

  4.   

    declare @int_count int
    declare @nvar_sql nvarchar(2000)
    set @nvar_sql='select @a=count(*) from testtbl'
    exec sp_executesql @nvar_sql,N'@a int output',@int_count output