代码改变世界

存储过程VMMS—审核

2012-07-24 13:45  Patrick.Lee  阅读(331)  评论(0编辑  收藏  举报

CREATE PROCEDURE AuditBook
    @ORDERMST_CODE VARCHAR(32),
    @OPERATOR VARCHAR(20)
AS
IF EXISTS(SELECT * FROM CUS_ORDERMST WHERE ORDERMST_CODE = @ORDERMST_CODE)
BEGIN
DECLARE @STATION_CODE  VARCHAR(3), @ROUTE_CODE  VARCHAR(3), @NUMBER VARCHAR(3),@ORDERMST_ID VARCHAR(32)
DECLARE @ORDERSTATE_ID VARCHAR(32),@ORDREDTL_ID VARCHAR(32)
DECLARE @PLTS DECIMAL,@PKG_QTY DECIMAL,@TTL_QTY DECIMAL,@GW DECIMAL,@NW DECIMAL,@AMOUNT DECIMAL

SELECT  @ORDERMST_ID = ORDRMST_ID,@ROUTE_CODE =  ROUTE_CODE  FROM CUS_ORDERMST WHERE ORDERMST_CODE = @ORDERMST_CODE

DECLARE  CURCUS_ORDERDTL CURSOR FOR
SELECT PLTS,PKG_QTY,TTL_QTY,GW,NW,AMOUNT FROM CUS_ORDERDTL WHERE ORDERMST_ID = @ORDERMST_ID

DECLARE  CURCOM_ROUTESTATION CURSOR FOR
SELECT STATION_CODE,NUMBER FROM COM_ROUTESTATION WHERE ROUTE_CODE = @ROUTE_CODE ORDER BY NUMBER

OPEN CURCOM_ROUTESTATION
FETCH NEXT FROM CURCOM_ROUTESTATION INTO @STATION_CODE,@NUMBER
WHILE @@FETCH_STATUS = 0
BEGIN
  OPEN CURCUS_ORDERDTL
  FETCH NEXT FROM CURCUS_ORDERDTL INTO @PLTS ,@PKG_QTY ,@TTL_QTY ,@GW ,@NW ,@AMOUNT
  WHILE @@FETCH_STATUS = 0
  BEGIN
    EXECUTE  GetSequenceNo 'CUS_ORDERSTATE','ORDERSTATE_ID',1,@ORDERSTATE_ID OUTPUT                                                       
    INSERT INTO CUS_ORDERSTATE(ORDERSTATE_ID,ORDERMST_ID,ORDERDTL_ID,PLTS,PKG_QTY,TTL_QTY,GW,NW,AMOUNT) VALUES(@ORDERSTATE_ID,@ORDERMST_ID,@ORDREDTL_ID,@PLTS ,@PKG_QTY ,@TTL_QTY ,@GW ,@NW ,@AMOUNT)
    FETCH NEXT FROM CURCUS_ORDERDTL INTO @PLTS ,@PKG_QTY ,@TTL_QTY ,@GW ,@NW ,@AMOUNT
  END
END
END
GO