怎么让存储过程既返回一个记录集,又能返回来一个普通的值

shixueli 2004-10-18 10:51:22
比如
select * from table1
return (select count(*) from table1)

但好像delphi不支持这样的用法,只能取得记录集,最后返回的那个值总是为0
不知为何
...全文
170 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
shixueli 2004-10-19
  • 打赏
  • 举报
回复
大家没有注意一个事实,
Select @Out=@RecCount
Select * from UserDatum
这两个语句不能反过来写,否则返回参数没有意义。
还是 DelphiAndJava2008(中国软件) 的回答富有建议性

helodd(真可爱) 的NextRecordset()也很有用,不过我用的是TStoredProc,这个组件没有该方法
DelphiAndJava2008 2004-10-19
  • 打赏
  • 举报
回复
这样可以满足你的要求:
在SQLSERVER中写过程
CREATE PROCEDURE MyPro
@Out int out
AS
begin
declare @RecCount int
Select @RecCount=Count(UserID) from UserDatum
Select @Out=@RecCount
Select * from UserDatum
end
GO
在DELPHI中调用:
procedure TForm1.Button1Click(Sender: TObject);
var
Tmp : integer;
begin
ADOStoredProc1.Open;
Tmp := ADOStoredProc1.Parameters.ParamByName('@Out').Value;
Self.Caption := inttostr(Tmp);
end;
searoom 2004-10-19
  • 打赏
  • 举报
回复
在存储过程里面可以使用输出参数,
怎么做是 sqlserver 的事情(如果这个不知道,去 sqlserver 版问)

然后在 taodquery 控件中执行存储过程

var
Param3:integer;

with aQuery do
begin
close;
sql.text:='exec proname param1,param2,:param3 output';
open;
iParam3:=Parameters.ParamByName('param3').value;
end;

绝对可行
helodd 2004-10-19
  • 打赏
  • 举报
回复
使用输出参数
create proc test
@a output
as
select * from table1
select @a=count(*) from table1


设用过程后取出参数的值就是了
helodd 2004-10-19
  • 打赏
  • 举报
回复
可以直接

select * from table1
select count(*) from table1

从Dataset 里面的记录集就是了...如果是多个可以用NextRecordset()
shixueli 2004-10-19
  • 打赏
  • 举报
回复
我的意思是返回一个记录集的同时,还返回另外一个值,比如这个记录集的记录数(不一定的,也有可能是自己声明的变量)。我想用DBGrids显示记录集,同时用showmessage把另外一个值打印出来,但结果总是为0
herman~~ 2004-10-18
  • 打赏
  • 举报
回复
不太明白楼主的意思
如果要返回一个结果集调用sql语句可以这样写:“select * from (select * from tabel)a ”
shixueli 2004-10-18
  • 打赏
  • 举报
回复
??

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧