tempad
Readygo技术搜索引擎 >>游戏开发 >> 存储过程的问题,返回不了变量....

存储过程的问题,返回不了变量....

Readygo技术搜索引擎 网络搜索 efish 2008-1-17 2:00:55

存储过程的问题,返回不了变量....

楼主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

责任编辑: efish 参与评论 查找更多:
相关文章
谁帮我看看这行代码 谁帮我看看这行代码
怎么样可以减少flash 的容量??? 怎么样可以减少flash 的容量???
Xmanager 里的字体问题 Xmanager 里的字体问题
提示asp.net版本不对问题 提示asp.net版本不对问题
vb中如何限制鼠标移动?急!! vb中如何限制鼠标移动?急!!
诸位兄弟,本人以前是用VB的,现在想学DELPHI,这里问一… 诸位兄弟,本人以前是用VB的,现在想学DELPHI,这里问一个简单问题
VideoServerPackagev093.zip VideoServerPackagev093.zip
如何清理数据库日志文件 如何清理数据库日志文件
我使用的是InterBase6.5,但发现要将原有的字段长度修… 我使用的是InterBase6.5,但发现要将原有的字段长度修改的少些就不行了,能解决这个问题吗?
在.aspx页面中添加了javascript代码,总体是控件没定… 在.aspx页面中添加了javascript代码,总体是控件没定义?帮忙看看了!
2秒记住本站域名

玩过泡泡龙吗?Readygo?Go! 再加上.Com.Cn的后缀,那就是大名小顶的readygo.com.cn

分类导航
Readygo技术搜索引擎