先试试这个:
declare @strSQL varchar(200)
declare @intRootRecordCount int
declare @strP
set @strP='where sex=1'
set @strsql='select '+@intRootRecordCount+'=count(*) from [friend_userinfo]' +@strp
exec (@strsql)

解决方案 »

  1.   

    这是变量的作用域问题。
    你声明@intRootRecordCount可以用动态语句来声明就可以解决了。
    declare @dec varchar(8000)
    select @dec='declare @intRootRecordCount int'
    在exec(@strsql)的时候,改成exec(@dec+@strsql)就可以了。或者set @strsql=@dec+'select @intRootRecordCount=count(*) from [friend_userinfo]' +@strp
    exec(@strsql)
      

  2.   

    我一般用 capcom(努力工作ing) 的方法
      

  3.   

    不行再试试这个!declare @strSQL nvarchar(200)
    declare @intRootRecordCount int
    declare @strP
    set @strP='where sex=1'
    set @strsql='select @intRootRecordCount=count(*) from [friend_userinfo]' +@strp
    exec sp_executesql @strsql,N'@intRootRecordCount int output',@intRootRecordCount output
      

  4.   

    呵呵,我试了, capcom的可以