你需要什么样的语名呀,
BEGIN TRANSACTION
SELECT @PDBH=0
SELECT @PDBH=MAX(CHECKCODE) FROM STO_CHECK
SELECT @PDBH=ISNULL(@PDBH,0)+1
UPDATE STO_LSCHECK SET CHECKCODE=@PDBH
IF @@error!=0
BEGIN
ROLLBACK TRANSACTION
RETURN -10000
END
INSERT INTO STO_CHECK SELECT * FROM STO_LSCHECK
IF @@error !=0
BEGIN
ROLLBACK TRANSACTION
RETURN -10000
END
DECLARE CHECK_CUR CURSOR FOR
SELECT METCODE,ACCOUNTSUM,FACTSUM,CHECKER,CHECKTIME FROM STO_LSCHECK WHERE ACCOUNTSUM<>FACTSUM
OPEN CHECK_CUR
FETCH NEXT FROM CHECK_CUR INTO @WZBH,@ZMSL,@SPKC,@PDR,@PDSJ
WHILE @@FETCH_STATUS =0
BEGIN
SELECT @YKSL=@SPKC-@ZMSL
SELECT @LSH=0
SELECT @LSH=MAX(ORDERCODE) FROM STO_INANDOUT
SELECT @LSH=ISNULL(@LSH,0)+1
IF @YKSL>0
BEGIN --盘盈,库存量增加,平均成本下降
SELECT @KCCB=STOCOST FROM STO_METINFO WHERE METCODE=@WZBH
INSERT INTO STO_INANDOUT ( ORDERCODE,METCODE,SUPPLY,AMOUNT,INOUTSIGN,INOUTSHAPE,TRANSACTOR,TRANSTIME,STONUMBER,STOCOST)
VALUES (@LSH,@WZBH,'盘点',@YKSL,'I','R',@PDR,@PDSJ,@SPKC,@KCCB)
IF @@ERROR !=0
BEGIN
CLOSE CHECK_CUR
DEALLOCATE CHECK_CUR
ROLLBACK TRANSACTION
RETURN -10000
END
END
ELSE
BEGIN --盘亏,库存量减少,平均成本上升
SELECT @KCCB=STOCOST FROM STO_METINFO WHERE METCODE=@WZBH
SELECT @YKSL=ABS(@YKSL)
INSERT INTO STO_INANDOUT ( ORDERCODE,METCODE,SUPPLY,SHIPMENT,INOUTSIGN,INOUTSHAPE,TRANSACTOR,TRANSTIME,STONUMBER,STOCOST)
VALUES (@LSH,@WZBH,'盘点',@YKSL,'O','D',@PDR,@PDSJ,@SPKC,@KCCB)
IF @@ERROR !=0
BEGIN
CLOSE CHECK_CUR
DEALLOCATE CHECK_CUR
ROLLBACK TRANSACTION
RETURN -10000
END
END
UPDATE STO_METINFO SET STONUMBER=@SPKC WHERE METCODE=@WZBH
IF @@ERROR !=0
BEGIN
CLOSE CHECK_CUR
DEALLOCATE CHECK_CUR
ROLLBACK TRANSACTION
RETURN -10000
END
FETCH NEXT FROM CHECK_CUR INTO @WZBH,@ZMSL,@SPKC,@PDR,@PDSJ
END
DELETE FROM STO_LSCHECK
IF @@ERROR !=0
BEGIN
CLOSE CHECK_CUR
DEALLOCATE CHECK_CUR
ROLLBACK TRANSACTION
RETURN -10000
END
CLOSE CHECK_CUR
DEALLOCATE CHECK_CUR
COMMIT TRANSACTION
RETURN 0
GO
这些够了吧