查询存储过程没有查询到数据,在线等!!谢谢!
本帖最后由 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