先试试这个:
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)
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)
你声明@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)
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