如果一个存贮过程中查询了几个表,那么最终返回的是那个表?

gxsuyong 2006-08-03 01:47:38
如果一个存贮过程中查询了几个表,那么最终返回的是那个表?我在一个存贮过程中对几个表查询,插入及合并,最终会返回那个表给调用程序?如果想返回最后一个表可以吗?为什么我的存贮过程返回的是例数第二个呢?
...全文
222 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
jsu_sz 2006-12-15
  • 打赏
  • 举报
回复
楼主,我已经发了一个解决这个问题的例子给你,请查看.
sp4 2006-08-07
  • 打赏
  • 举报
回复
当然是有几个有返回几个
gxsuyong 2006-08-05
  • 打赏
  • 举报
回复
我只想要返回最后一个,要加什么语句吗?谢谢!!!
hellowork 2006-08-03
  • 打赏
  • 举报
回复
如果使用ADO来执行存储过程的话,只会返回第一个查询结果集,如果要继续返回之后的查询结果集,必须调用ADO.NEXTRECORD方法,然后判断RECORDSET对象的STATE状态,如果oRecordSet.state = adStateClosed,则表明没有其它结果集返回了,RecordSet就自动关闭了.
如果使用select * from openrowset('sqloledb','Trusted_Connection=yes','exec dbname.dbo.spname'),返回的也是第一个查询结果集.
如果在查询分析器中EXEC SP,会返回所有查询结果集.
gahade 2006-08-03
  • 打赏
  • 举报
回复
有几句输出的就返回几个
gahade 2006-08-03
  • 打赏
  • 举报
回复
WangZWang(先来)
返回的是最后一个
-----------------------------------------------------------------------------
不是返回最后一个,有几句select返回几个
gxsuyong 2006-08-03
  • 打赏
  • 举报
回复
我想返回的是最后操作的表,可是返回的是testQueryall

declare @start_date datetime
set @start_date=(select dateadd(mm,datediff(mm,0,getdate()),0))

--select [id]=identity(int,1,1),* into #T from testQuery
select [id]=identity(int,1,1),* into #TB from T_testQuery
select start_date=@start_date,
A.inrefno,A.indate,A.incbm,A.outrefno,A.outdate,B.outcbm,B.bcbm,A.仓内搬运,A.叉车使用费,A.卡板费 into testqueryall
from #TB A,(select min(id) as id,inrefno,outrefno,sum(incbm)as incbm,sum(outcbm)as outcbm,datediff(day,indate,outdate) as mydate,sum(bcbm)as bcbm from #TB group by inrefno,outrefno,indate,outdate)B
where A.id=B.id

drop table #TB


-- 建最终表,并通过游标重复有出货的记录,求天数---
create table Temp_A
(
StartDate datetime,
inrefno varchar(20),
incbm decimal(18,2),
outrefno varchar(20),
outdate datetime,
outcbm int,
bcbm decimal(18,2),
myday int,
仓内搬运 decimal(18,2),
叉车使用费 decimal(18,2),
卡板费 decimal(18,2)
)


-----------游标-----------
Declare T_SC cursor for Select start_date,inrefno,incbm,outrefno,outdate,outcbm,bcbm,仓内搬运,叉车使用费,卡板费 from testqueryall
Declare @Startdate datetime
Declare @inrefno varchar(20)
Declare @incbm decimal(18,2)
Declare @outrefno varchar(20)
Declare @outdate datetime
Declare @outcbm int
Declare @bcbm decimal(18,2)
Declare @仓内搬运 decimal(18,2)
Declare @叉车使用费 decimal(18,2)
Declare @卡板费 decimal(18,2)
open T_SC

fetch next from T_SC into @StartDate,@inrefno,@incbm,@outrefno,@outdate,@outcbm,@bcbm,@仓内搬运,@叉车使用费,@卡板费
while @@FETCH_STATUS=0
begin
if @outdate is not null
begin
insert Temp_A select @StartDate,@inrefno,@incbm,@outrefno,@outdate,@outcbm,@bcbm,datediff(dd,@StartDate,@outdate),@仓内搬运,@叉车使用费,@卡板费
insert Temp_A select
@StartDate,@inrefno,@bcbm,null,null,null,@bcbm,datediff(dd,@StartDate,cast(year(@StartDate)as varchar)+ '-' +
cast(month(@StartDate)+1 as varchar)+ '-01'),@仓内搬运,@叉车使用费,@卡板费
end
else
insert Temp_A select
@StartDate,@inrefno,@incbm,@outrefno,@outdate,@outcbm,@bcbm,datediff(dd,@StartDate,cast(year(@StartDate) as varchar)+
'-'+ cast(month(@StartDate)+1 as varchar) + '-01'),@仓内搬运,@叉车使用费,@卡板费
fetch next from T_SC into @StartDate,@inrefno,@incbm,@outrefno,@outdate,@outcbm,@bcbm,@仓内搬运,@叉车使用费,@卡板费
end
close T_SC
deallocate T_SC

select * from Temp_A
drop table temp_A

drop table #testinrefno
drop table testTempO
drop table testTempO2
drop table testTempI
drop table testTempI2
drop table testquery
drop table T_testQuery
drop table testqueryall
GO
gxsuyong 2006-08-03
  • 打赏
  • 举报
回复
那怎么我的程序中显示的不是最后一个呢?
WangZWang 2006-08-03
  • 打赏
  • 举报
回复
返回的是最后一个,请贴出你的proc

27,580

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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