delphi存储过程的一个问题

earths 2006-03-30 04:44:15
我在报表(主从报表)要用到存储过程,比如主表select mainid , from maintbl
从表是存储过程 比如 create sp_test @mainid integer as select mainid ,subid from subtbl where mainid=@mainid 当然实际上从表的存储过程是比较复杂的,我想知道如何把主表的mainid作为参数传递到从表的存储过程中,谢谢了
...全文
202 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
todouwang 2006-04-05
  • 打赏
  • 举报
回复
1400行的存储过程.....,难道不能分解么?调试起来也简单呀
earths 2006-04-03
  • 打赏
  • 举报
回复
各个高手们,根据大家提供的方法,好像还是不能够解决,可能我的存储过程比较复杂,共写了1400行的psql,我如果用sp简单直接读表,是可以的,但是换成我写的那堆代码,就不可以了????
todouwang 2006-03-31
  • 打赏
  • 举报
回复
create table #temp1(id int,num int)
insert into #temp1
select mainid,0 from maintbl
你这样如果还不能取得你想要的mainID,那你要看看你的main表中到底有几个适合的mainID了
sxdoujg 2006-03-31
  • 打赏
  • 举报
回复
看修正版本!
earths 2006-03-31
  • 打赏
  • 举报
回复
谢谢sxdoujg和78hgdong提高的思路,可能是我表达不够明白,我的意识是要从子表得到结果集,主从关系的,当然我们如果直接用代码处理是可以的,但是我目前做报表,只能想办法把主表的mainid转递到从表来,create table #temp1(id int,num int)
insert into #temp1
select mainid from maintbl 实际上只有一个mainid转递过来,但是没有办法传递
sxdoujg 2006-03-31
  • 打赏
  • 举报
回复
直接用存贮过程!修正版本
CREATE PROCEDURE usp_test AS
declare @mainid char(20)
declare @count int

create table #temp1(id int)
insert into #temp1
select mainid from maintbl

declare read_userid cursor for select mainid ,subid from subtbl
select @count=count(id) from subtbl
if @count>0
begin
open read_userid

while @count>0
begin
fetch next from read_userid into @mainid

if exists( select * from subtbl where id=@mainid )
begin
--希望地操作
end
set @count=@count-1
end
commit transaction
end
deallocate read_userid


GO
sxdoujg 2006-03-31
  • 打赏
  • 举报
回复
直接用存贮过程!
CREATE PROCEDURE usp_test AS
declare @mainid char(20)
declare @count int

create table #temp1(id int,num int)
insert into #temp1
select mainid from maintbl

declare read_userid cursor for select mainid ,subid from subtbl
select @count=count(id) from subtbl
if @count>0
begin
open read_userid
----------------------------------------------------------------------------------------------------------------------------while begin
while @count>0
begin
fetch next from read_userid into @mainid
--读取数量金额表
if exists( select * from subtbl where id=@mainid )
begin
--希望地操作
end
set @count=@count-1
end
---------------------------------------------------------------------------------------------------------------------------while end
commit transaction
end
deallocate read_userid
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------定义游标end

GO
earths 2006-03-31
  • 打赏
  • 举报
回复
如果用SQL,可以设置子表的masterfield和indexfield进行关联,但是储存过程,好像没有办法
cheng525jj 2006-03-31
  • 打赏
  • 举报
回复
好好整理一下,再来看吧.
78hgdong 2006-03-30
  • 打赏
  • 举报
回复
在从表中USE MAINFRM
把查询出来的mainid 存入的从表的一个变量中,
再传进存储过程的参数@BB...

2,507

社区成员

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

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