读书人

查询存储过程没有查询到数据多谢

发布时间: 2014-01-17 00:06:00 作者: rapoo

查询存储过程没有查询到数据,在线等!!谢谢!
本帖最后由 zuoan2008 于 2014-01-13 11:17:17 编辑 我的存储过程:


set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER PROCEDURE [dbo].[WHM_OrderSituation]
(@result int output)
AS
BEGIN
create table #tmp
(
oorder varchar(20),
orderdate varchar(20),
pcenddate varchar(20),
[name] varchar(20),
cloth varchar(20),
color varchar(20),
ssize1 varchar(20),
ssize2 varchar(20),
note varchar(200),
isnotsc char(10),
scqty int,
ykqty int,
syqty int
)
--delete from #tmp
---开始数据
declare
@tempoorder varchar(20),
@temporderdate varchar(20),
@temppcenddate varchar(20),
@tempname varchar(20),
@tempcloth varchar(20),
@tempcolor varchar(20),
@tempssize1 varchar(20),
@tempssize2 varchar(20),
@tempnote varchar(200),
@tempisnotsc char(10),
@tempscqty int,
@tempykqty int,
@tempsyqty int

declare cur cursor
for select a.oorder,a.orderdate,c.pcenddate,b.name,b.cloth,b.color,b.ssize1,b.ssize2,b.note,b.isnotsc,b.scqty from WHM.dbo.ordertable a left join WHM.dbo.orderclass b on a.oorder =b.oorder left join MES.dbo.mes_orderpc c on a.oorder=c.pcorder where a.status='1'
Open cur
fetch next from cur into @tempoorder, @temporderdate,@temppcenddate,@tempname,@tempcloth,@tempcolor,@tempssize1,@tempssize2,@tempnote,@tempisnotsc,@tempscqty
while (@@Fetch_Status=0)
begin
if(exists(select sum(amount) as qty from WHM.dbo.dordertable where dorder=@tempoorder and name=@tempname and cloth=@tempcloth and color=@tempcolor and ssize1=@tempssize1 and ssize2=@tempssize2 and note =@tempnote))
begin
select @tempykqty = sum(amount) from WHM.dbo.dordertable where dorder=@tempoorder and name=@tempname and cloth=@tempcloth and color=@tempcolor and ssize1=@tempssize1 and ssize2=@tempssize2 and note =@tempnote
end
else
begin
set @tempykqty=0
end
set @tempsyqty=@tempscqty-@tempykqty
update #tmp set ykqty=@tempykqty,syqty=@tempsyqty where oorder=@tempoorder and name=@tempname and cloth=@tempcloth and color=@tempcolor and ssize1=@tempssize1 and ssize2=@tempssize2 and note =@tempnote
fetch next from cur into @tempoorder, @temporderdate,@temppcenddate,@tempname,@tempcloth,@tempcolor,@tempssize1,@tempssize2,@tempnote,@tempisnotsc,@tempscqty


end


Close cur --关闭游标
Deallocate cur --释放游标

select oorder,orderdate,pcenddate,[name],cloth,color,ssize1,ssize2,note,isnotsc,scqty,ykqty,syqty from #tmp
set @result=0


END



我用单条语句去查询的时候有查询到数据的
select a.oorder,a.orderdate,c.pcenddate,b.name,b.cloth,b.color,b.ssize1,b.ssize2,b.note,b.isnotsc,b.scqty from WHM.dbo.ordertable a left join WHM.dbo.orderclass b on a.oorder =b.oorder left join MES.dbo.mes_orderpc c on a.oorder=c.pcorder where a.status='1'
是有数据的


应该是我存储过程的问题了,请问号是怎么回事?
请各位大侠帮忙看看,谢谢!
[解决办法]
你可以先在游标里面保留if的逻辑,看看有没有数据,如果没有,那就应该是if的问题,没有环境不知道怎么给你测,目测可能在if(exists)那部分,你可以试试if(select sum)IS not null这样的判断
[解决办法]
我看了你的代码,你的代码中定义了一个临时表 #tmp,

但是,你在代码中只是update #tmp ,并没有把数据插入到#tmp,所以最后select * from #tmp 肯定不会返回结果的
[解决办法]
句中有插入表?

读书人网 >SQL Server

热点推荐