標籤:style color os strong for re
declare @dingdanid int declare @fanhuizhi int
set @dingdanid = 1
exec 檢測訂單出庫資格 @dingdanid ,@fanhuizhi output (注意別忘了output否則傳回值是NULL)
select @fanhuizhi
create proc dbo.檢測訂單出庫資格
@dingdanID int, @returnValue int output
as
-- 輸入變數 訂單編號
set @returnValue = 1
-- 監測訂單的出庫資格
-- 如果已出庫,返回0
-- 如果未出庫並且該訂單所屬的總成需求量均小於等於庫存,即滿足出庫狀態,返回1e;否則返回0
if ‘已出庫‘ = (select 訂單狀態 from 訂單1 where 訂單編號 = @dingdanID)
begin
set @returnValue = 0
return @returnValue
end
declare @zongchengID nvarchar(50)
declare @chazhi int
DECLARE Employee_Cursor CURSOR FOR select 訂單2.總成編號,(庫存量- sum(訂單2.需求數量)) as 差值 from 訂單2 , 總成表 where 訂單編號[email protected] and 訂單2.總成編號 = 總成表.總成編號 group by 訂單2.總成編號,庫存量 OPEN Employee_Cursor
FETCH NEXT FROM Employee_Cursor into @zongchengID,@chazhi
WHILE @@FETCH_STATUS = 0 BEGIN
if(@chazhi <0 )
begin set @returnValue = 0
return @returnValue
break
end
FETCH NEXT FROM Employee_Cursor into @zongchengID,@chazhi END
CLOSE Employee_Cursor
DEALLOCATE Employee_Cursor
return @returnValue