存储过程的问题,返回不了变量....
存储过程的问题,返回不了变量....
楼主nill(麒麟)2004-03-25 13:11:05 在 MS-SQL Server / 基础类 提问 declare @strSQL varchar(200)
declare @intRootRecordCount int
declare @strP
set @strP="where sex=1"
set @strsql="select @intRootRecordCount=count(*) from " +@strp
exec (@strsql)
系统提示:
必须声明变量 "@intRootRecordCount"。
这是我简化了的例子,我需要在很多地方用到count(*)的值,和需要重新对strP赋值
问题点数:0、回复次数:6Top
1 楼capcom(努力工作ing)回复于 2004-03-25 13:19:35 得分 0
先试试这个:
declare @strSQL varchar(200)
declare @intRootRecordCount int
declare @strP
set @strP="where sex=1"
set @strsql="select "+@intRootRecordCount+"=count(*) from " +@strp
exec (@strsql)Top
2 楼lovvver(ElephantTalk.Bright)回复于 2004-03-25 13:19:51 得分 0
这是变量的作用域问题。
你声明@intRootRecordCount可以用动态语句来声明就可以解决了。
declare @dec varchar(8000)
select @dec="declare @intRootRecordCount int"
在exec(@strsql)的时候,改成exec(@dec+@strsql)就可以了。或者
set @strsql=@dec+"select @intRootRecordCount=count(*) from " +@strp
exec(@strsql)
Top
3 楼Mybeautiful(天之痕)回复于 2004-03-25 13:21:46 得分 0
我一般用 capcom(努力工作ing) 的方法Top
4 楼capcom(努力工作ing)回复于 2004-03-25 13:22:47 得分 0
不行再试试这个!
declare @strSQL nvarchar(200)
declare @intRootRecordCount int
declare @strP
set @strP="where sex=1"
set @strsql="select @intRootRecordCount=count(*) from " +@strp
exec sp_executesql @strsql,N"@intRootRecordCount int output",@intRootRecordCount output
Top
5 楼nill(麒麟)回复于 2004-03-25 13:40:29 得分 0
N" 是什么意思?我在联机帮助看到类似这个例子,Top
6 楼janelyyhshi(jane)回复于 2004-03-25 14:10:45 得分 0
呵呵,我试了, capcom的可以
Top
-
相关文章
2秒记住本站域名
玩过泡泡龙吗?Readygo?Go! 再加上.Com.Cn的后缀,那就是大名小顶的readygo.com.cn
