1. 程式人生 > >條碼系統的 儲存過程 示例

條碼系統的 儲存過程 示例

這個是sql sever的儲存過程,以後要改成oracle的

手持式條碼機批量掃描條碼後,無線上傳到伺服器,伺服器後臺通過儲存過程自動生產對應的資料。

USE [Barcode]

GO


/****** Object:  StoredProcedure [dbo].[ds_insertPURTG]    Script Date: 03/16/2016 09:23:28 ******/
SET ANSI_NULLS ON
GO


SET QUOTED_IDENTIFIER ON
GO


--把條碼資料庫的內容,進行轉到ERP裡去(實行一次行全部轉移)
ALTER   PROCEDURE [dbo].[ds_insertPURTG] 
@optcode varchar(10)
AS
declare @TG001   CHAR(4),  --單別
@TG002  CHAR(11),  --單號
@TG003 CHAR(8),  --進貨日期
@TG004 CHAR(6), --工廠編號
@TG005 CHAR(10) ,----供應商編號
@TG007  CHAR(4), --幣種
@TG008 numeric(10,6),  --匯率
@TG009 char(1),  --發票種類
@TG010 CHAR(1),  --稅種  1:內涵,2外加,其他:0
@TG021   CHAR(72),  --供應商全稱
@TG030     numeric(5,4),  --稅率
@TG033    char(6), --付款條件編號
@MF004  CHAR(10),
@createdate char(17), --進貨建立日期
@TD001 CHAR(4),  --採購單別
@TD002 CHAR(11),--採購單號
@TD003 CHAR(4),--採購序號
@amount numeric(18,6), --本次送貨數量
@amount1 numeric(18,6),  --本次驗收數量
@boxAmount numeric(18,6),--本次送貨包裝數量
@boxAmount1 numeric(18,6),  --本次入庫包裝數量
@backAmount numeric(18,6),  --退回數量
@boxBackAmount numeric(18,6),  --退回包裝數量
@JJAmount NUMERIC(18,6) ,--代表計價數量
@XH NUMERIC(9),  ---定義序號
@TH045 NUMERIC(11,2),   --原幣稅前金額 
@TH046 NUMERIC(11,2),   --原幣稅額
@TH047 NUMERIC(11,2),   --本幣稅前金額
@TH048 NUMERIC(11,2),   ---本幣稅額
@TA006 CHAR(10),     --檢驗人員
@DHID INT ,--到貨ID
@YSID INT ,--驗收ID
@QRID INT , --確認ID
@CC001 CHAR(4),
@CC002 CHAR(11),
@CC003 CHAR(8), --到貨日期
@TA004 CHAR(8),--檢驗日期
@DHoptcode CHAR(10), --到貨人員
@DHcreatedate CHAR(17), --到貨建立日期
@YScreatedate CHAR(17),--驗收建立日期
@amountpk  numeric(18,3),  --平庫數量
@amountgk  numeric(18,3),   --高庫數量
@TC001 CHAR(4),
@TC002 CHAR(11)
begin transaction
---先進行取得進貨單別,再單據性質裡,必須設定標識,UDF01='Y'則,進行取的
--SELECT @TG001=MQ001 FROM EGP..CMSMQ WHERE MQ003='34' AND UDF01='Y'  
        ---//原來條形碼掃描生成ERP進貨單,單別都是340,現在想分開,採購單別為330的生成進貨單別340,採購單別為331的生成進貨單別342
SELECT @CC001=MQ001 FROM EGP..CMSMQ WHERE MQ003='37' AND UDF01='Y'--取到貨單別
--取得工廠資訊
SELECT @TG004=MB001 FROM EGP..CMSMB
    --SELECT @TG003=CONVERT(CHAR(8),GETDATE(),112)
SELECT @MF004=MF004 FROM EGP..ADMMF WHERE
[email protected]

--select @createdate=replace(replace(replace(replace(CONVERT(CHAR(23),GETDATE(),121),'-',''),':',''),'.',''),' ','')



--開始定義遊標,以供應商為導向
DECLARE MYCURSOR CURSOR FOR 
SELECT DISTINCT TC004,TC001,TC002  FROM barcode_PURTC WHERE status='0' AND [type]='確認' AND [email protected] ORDER BY TC004


OPEN MYCURSOR
FETCH MYCURSOR INTO
@TG005,@TC001,@TC002
WHILE @@FETCH_STATUS=0
BEGIN
        IF  @TC001='330' OR @TC001='332'
BEGIN
SET @TG001='340'
END
IF  @TC001='331'
BEGIN
SET @TG001='342'
         END
--單別都是340,現在想分開,採購單別為330的生成進貨單別340,採購單別為331的生成進貨單別342
        --取確認,驗收,到貨ID
        SELECT  top 1 @QRID=[id],@YSID=relbillid FROM barcode_PURTC WHERE status='0' AND [type]='確認' AND
[email protected]
 
        SELECT  @DHID=relbillid,@TA004=CONVERT(CHAR(8),optdatetime,112), @YScreatedate=replace(replace(replace(replace(CONVERT(CHAR(23),optdatetime,121),'-',''),':',''),'.',''),' ','') FROM barcode_PURTC WHERE [email protected] 
        SELECT @TG003=CONVERT(CHAR(8),optdatetime,112),@createdate=replace(replace(replace(replace(CONVERT(CHAR(23),optdatetime,121),'-',''),':',''),'.',''),' ','') from barcode_PURTC WHERE
[email protected]
 --取進貨時間
        SELECT @CC003=CONVERT(CHAR(8),optdatetime,112),@DHoptcode=optcode,@DHcreatedate=replace(replace(replace(replace(CONVERT(CHAR(23),optdatetime,121),'-',''),':',''),'.',''),' ','') from barcode_PURTC WHERE [email protected]  --取到貨時間
SELECT @CC002=CAST(CAST(ISNULL(MAX(CC002),CONVERT(CHAR(8),GETDATE(),112)+'000') AS NUMERIC(11))+1  AS CHAR(11))   FROM EGP..PURCC WHERE CC003=CONVERT(CHAR(8),GETDATE(),112)


        --取檢驗人員 
SELECT  @TA006=optcode from barcode_PURTC WHERE [email protected]
----取得單號 ---此種方式適合於編碼為日遍的客戶
SELECT @TG002=CAST(CAST(ISNULL(MAX(TG002),CONVERT(CHAR(8),GETDATE(),112)+'000') AS NUMERIC(11))+1  AS CHAR(11))   FROM EGP..PURTG WHERE  [email protected] and TG002 LIKE CONVERT(CHAR(8),GETDATE(),112)+'%'--使用TG003代替getdate(),避免因輸入日期不一致,導致單號重複

SELECT @TG021=MA003,@TG009=MA030,@TG010=MA044,@TG030=MA064,@TG033=MA025 FROM EGP..PURMA WHERE [email protected]  [email protected]=MA021供應商資訊改為取採購訂單
SELECT @TG007=TC005 FROM EGP..PURTC WHERE [email protected] AND [email protected]  --20130225 修改.
select top 1 @TG008=ISNULL(MG004,1) from EGP..CMSMG WHERE [email protected] AND MG002<= CONVERT(CHAR(8),GETDATE(),112) ORDER BY MG002 DESC


--插入到貨單
/*


INSERT EGP..PURCC
SELECT 'EGP',optcode,(SELECT MF004 FROM EGP..ADMMF WHERE MF001=optcode),@DHcreatedate,'','',1,@CC001,@CC002,@CC003,@TG004,
TC004,'',0,'','Y' AS CC009,@CC003,'',@TG021,0,0,optcode,'','','','',0,0,'N','','',0,'','N','','','','','','',0,0,0,0,0,0,
'','','','','','',0,0,0,0,0,0
FROM barcode_PURTC WHERE status='0' AND [email protected]



--插入到貨單單身
    INSERT EGP..PURCD
    SELECT 'EGP',optcode,(SELECT MF004 FROM EGP..ADMMF WHERE MF001=optcode),@DHcreatedate,'','',1,@CC001,@CC002,barcode_PURTD.TD003,
    TD004,TD005,TD006,TD009,amount1,0,TD001,TD002,barcode_PURTD.TD003,TD008,0,TD009,TD007,'',amount1,
    0,0,TD009,'',boxAmount1,0,0,0,0,0,0,0,0,0,'' AS CD033,'Y','',optcode,'','N','','',0,0,0,
    '','','','','','',0,0,0,0,0,0,'','','','','','',0,0,0,0,0,0
    FROM barcode_PURTC,barcode_PURTD WHERE barcode_PURTC.id=barcode_PURTD.billid AND barcode_PURTC.status='0' AND [email protected]
AND [email protected] AND [email protected]*/




UPDATE barcode_PURTC SET status='1' WHERE [id][email protected]

        --插入單頭資訊
INSERT EGP..PURTG
VALUES('EGP',@optcode,@MF004,@createdate,'','',1,@TG001,@TG002,@TG003,@TG004,@TG005,'',@TG007,@TG008,@TG009,@TG010,'',0,'N',@TG003,'N','',0,0,0,0,@TG021,'','1','N',0,0,'',0,'',@TG030,
0,0,@TG033,'','','','',0,0,0,0,'N','N','',0,0,'','','','N','','',0,0,0,'','',0,'','','','','','','',0,0,0,0,0,0,'','','','','','',0,0,0,0,0,0)
select @XH=1

                          ---進行迴圈單身插入
DECLARE MYDETAILCURSOR CURSOR FOR
SELECT TD001,TD002,barcode_PURTD.TD003,amount,amount1,boxAmount1,backAmount,boxBackAmount,JJAmount,amountpk,amountgk FROM barcode_PURTD,barcode_PURTC 
WHERE barcode_PURTD.billid=barcode_PURTC.id AND barcode_PURTC.status='0' AND [type]='確認' AND [email protected] AND [email protected] AND [email protected]
AND [email protected]


OPEN MYDETAILCURSOR 
FETCH MYDETAILCURSOR INTO
@TD001,@TD002,@TD003,@amount,@amount1,@boxAmount1,@backAmount,@boxBackAmount,@JJAmount,@amountpk,@amountgk
WHILE @@FETCH_STATUS=0
BEGIN
  IF  @amountpk<>0 AND @amountgk<>0 
  BEGIN
--高庫
INSERT EGP..PURTH
SELECT 'EGP',@optcode,@MF004,@createdate,'','',1,@TG001,@TG002,RIGHT('0000'+RTRIM(CAST(@XH AS CHAR(4))),4) AS TH003,TD004 AS TH004,TD005 AS TH005,TD006 AS TH006,@amountgk AS TH007,
TD009 AS TH008,TD007 AS TH009,TD021 AS TH010,TD001,TD002,TD003,@TG003,@amountgk,@amountgk,@backAmount,TD010 AS TH018,TD010*@amountgk AS TH019,0,'','','',   ---TH023
0,'','N','N' AS TH027,'2' AS TH028,'N','N','N','N',TD014,(CASE WHEN (EXISTS(SELECT * FROM EGP..INVMD WHERE MD001=TD004 AND MD002=TD009)) THEN @amountgk*(SELECT MD004/MD003 FROM EGP..INVMD WHERE MD001=TD004 AND MD002=TD009) ELSE @amountgk END) AS TH034,'','','','','','','','' AS TH042,'N','N', 
(CASE @TG010 WHEN '1' THEN TD010*@amountgk/([email protected])  ELSE TD010*@amountgk END)  AS TH045,
(CASE @TG010 WHEN '1' THEN TD010*@amountgk/([email protected])*@TG030  when '2' then TD010*@amountgk*@TG030 else 0 END)  AS TH046,
(CASE @TG010 WHEN '1' THEN TD010*@amountgk/([email protected])  ELSE TD010*@amountgk END) *@TG008 as TH047 ,
(CASE @TG010 WHEN '1' THEN TD010*@amountgk/([email protected])*@TG030  when '2' then TD010*@amountgk*@TG030 else 0 END) *@TG008 AS TH048,
@boxAmount,@boxAmount1,@boxBackAmount,0,TD032,0,0,'','',0,0,0 AS TH060,0,0,'',TD038,TD009,'','',0,0,'N',1,'gaoku','','','','',0,0,0,'N' AS TH080,
0,'2','','','','0001','0001','','','','','',TD201,0,0,0,0,0,0,'','','','','','',0,0,0,0,0,0 FROM 
EGP..PURTD WHERE [email protected] AND [email protected] AND [email protected]
  ----直接進行插入檢驗單頭檔
           INSERT EGP..QMSTA
           SELECT  'EGP',@TA006,@MF004,@YScreatedate,'','',1,@TG001,@TG002,RIGHT('0000'+RTRIM(CAST(@XH AS CHAR(4))),4) AS TH003,@TG003,@TG003,@TA006,0,
           0,0,'','2','4',0,'Y' AS TA014,'','','','',@TG003,@TA006,'N',0,0,0,0,'0001','允收',1,@TG003,'',0,0,0,'N' AS TA034,'','','','','','',0 AS TA041,0,0,0,0 AS TA045,0,0,0,'' as TAC04,0,'',0,0,0,'','','','',TD021,TD201,0,0,0,0,0,0,
           '','','','','','',0,0,0,0,0,0 FROM EGP..PURTD WHERE [email protected] AND [email protected] AND [email protected]

--平庫
INSERT EGP..PURTH
SELECT 'EGP',@optcode,@MF004,@createdate,'','',1,@TG001,@TG002,RIGHT('0010'+RTRIM(CAST(@XH AS CHAR(4))),4) AS TH003,TD004 AS TH004,TD005 AS TH005,TD006 AS TH006,@amountpk AS TH007,
TD009 AS TH008,TD007 AS TH009,TD021 AS TH010,TD001,TD002,TD003,@TG003,@amountpk,@amountpk,@backAmount,TD010 AS TH018,TD010*@amountpk AS TH019,0,'','','',   ---TH023
0,'','N','N' AS TH027,'2' AS TH028,'N','N','N','N',TD014,(CASE WHEN (EXISTS(SELECT * FROM EGP..INVMD WHERE MD001=TD004 AND MD002=TD009)) THEN @amountpk*(SELECT MD004/MD003 FROM EGP..INVMD WHERE MD001=TD004 AND MD002=TD009) ELSE @amountpk END) AS TH034,'','','','','','','','' AS TH042,'N','N', 
(CASE @TG010 WHEN '1' THEN TD010*@amountpk/([email protected])  ELSE TD010*@amountpk END)  AS TH045,
(CASE @TG010 WHEN '1' THEN TD010*@amountpk/([email protected])*@TG030  when '2' then TD010*@amountpk*@TG030 else 0 END)  AS TH046,
(CASE @TG010 WHEN '1' THEN TD010*@amountpk/([email protected])  ELSE TD010*@amountpk END) *@TG008 as TH047 ,
(CASE @TG010 WHEN '1' THEN TD010*@amountpk/([email protected])*@TG030  when '2' then TD010*@amountpk*@TG030 else 0 END) *@TG008 AS TH048,
@boxAmount,@boxAmount1,@boxBackAmount,0,TD032,0,0,'','',0,0,0 AS TH060,0,0,'',TD038,TD009,'','',0,0,'N',1,'##########','','','','',0,0,0,'N' AS TH080,
0,'2','','','','0001','0001','','','','','',TD201,0,0,0,0,0,0,'','','','','','',0,0,0,0,0,0 FROM 
EGP..PURTD WHERE [email protected] AND [email protected] AND [email protected]
  ----直接進行插入檢驗單頭檔
           INSERT EGP..QMSTA
           SELECT  'EGP',@TA006,@MF004,@YScreatedate,'','',1,@TG001,@TG002,RIGHT('0010'+RTRIM(CAST(@XH AS CHAR(4))),4) AS TH003,@TG003,@TG003,@TA006,0,
           0,0,'','2','4',0,'Y' AS TA014,'','','','',@TG003,@TA006,'N',0,0,0,0,'0001','允收',1,@TG003,'',0,0,0,'N' AS TA034,'','','','','','',0 AS TA041,0,0,0,0 AS TA045,0,0,0,'' as TAC04,0,'',0,0,0,'','','','',TD021,TD201,0,0,0,0,0,0,
           '','','','','','',0,0,0,0,0,0 FROM EGP..PURTD WHERE [email protected] AND [email protected] AND [email protected]
      END 
ELSE
  IF  @amountpk=0 AND @amountgk<>0 
  BEGIN
--高庫
INSERT EGP..PURTH
SELECT 'EGP',@optcode,@MF004,@createdate,'','',1,@TG001,@TG002,RIGHT('0000'+RTRIM(CAST(@XH AS CHAR(4))),4) AS TH003,TD004 AS TH004,TD005 AS TH005,TD006 AS TH006,@amountgk AS TH007,
TD009 AS TH008,TD007 AS TH009,TD021 AS TH010,TD001,TD002,TD003,@TG003,@amountgk,@amountgk,@backAmount,TD010 AS TH018,TD010*@amountgk AS TH019,0,'','','',   ---TH023
0,'','N','N' AS TH027,'2' AS TH028,'N','N','N','N',TD014,(CASE WHEN (EXISTS(SELECT * FROM EGP..INVMD WHERE MD001=TD004 AND MD002=TD009)) THEN @amountgk*(SELECT MD004/MD003 FROM EGP..INVMD WHERE MD001=TD004 AND MD002=TD009) ELSE @amountgk END) AS TH034,'','','','','','','','' AS TH042,'N','N', 
(CASE @TG010 WHEN '1' THEN TD010*@amountgk/([email protected])  ELSE TD010*@amountgk END)  AS TH045,
(CASE @TG010 WHEN '1' THEN TD010*@amountgk/([email protected])*@TG030  when '2' then TD010*@amountgk*@TG030 else 0 END)  AS TH046,
(CASE @TG010 WHEN '1' THEN TD010*@amountgk/([email protected])  ELSE TD010*@amountgk END) *@TG008 as TH047 ,
(CASE @TG010 WHEN '1' THEN TD010*@amountgk/([email protected])*@TG030  when '2' then TD010*@amountgk*@TG030 else 0 END) *@TG008 AS TH048,
@boxAmount,@boxAmount1,@boxBackAmount,0,TD032,0,0,'','',0,0,0 AS TH060,0,0,'',TD038,TD009,'','',0,0,'N',1,'gaoku','','','','',0,0,0,'N' AS TH080,
0,'2','','','','0001','0001','','','','','',TD201,0,0,0,0,0,0,'','','','','','',0,0,0,0,0,0 FROM 
EGP..PURTD WHERE [email protected] AND [email protected] AND [email protected]
  ----直接進行插入檢驗單頭檔
           INSERT EGP..QMSTA
           SELECT  'EGP',@TA006,@MF004,@YScreatedate,'','',1,@TG001,@TG002,RIGHT('0000'+RTRIM(CAST(@XH AS CHAR(4))),4) AS TH003,@TG003,@TG003,@TA006,0,
           0,0,'','2','4',0,'Y' AS TA014,'','','','',@TG003,@TA006,'N',0,0,0,0,'0001','允收',1,@TG003,'',0,0,0,'N' AS TA034,'','','','','','',0 AS TA041,0,0,0,0 AS TA045,0,0,0,'' as TAC04,0,'',0,0,0,'','','','',TD021,TD201,0,0,0,0,0,0,
           '','','','','','',0,0,0,0,0,0 FROM EGP..PURTD WHERE [email protected] AND [email protected] AND [email protected]
      END 
ELSE
BEGIN
INSERT EGP..PURTH
SELECT 'EGP',@optcode,@MF004,@createdate,'','',1,@TG001,@TG002,RIGHT('0000'+RTRIM(CAST(@XH AS CHAR(4))),4) AS TH003,TD004 AS TH004,TD005 AS TH005,TD006 AS TH006,@amount1 AS TH007,
TD009 AS TH008,TD007 AS TH009,TD021 AS TH010,TD001,TD002,TD003,@TG003,@amount1,@amount1,@backAmount,TD010 AS TH018,TD010*@JJAmount AS TH019,0,'','','',   ---TH023
0,'','N','N' AS TH027,'2' AS TH028,'N','N','N','N',TD014,(CASE WHEN (EXISTS(SELECT * FROM EGP..INVMD WHERE MD001=TD004 AND MD002=TD009)) THEN @amount1*(SELECT MD004/MD003 FROM EGP..INVMD WHERE MD001=TD004 AND MD002=TD009) ELSE @amount1 END) AS TH034,'','','','','','','','' AS TH042,'N','N', 
(CASE @TG010 WHEN '1' THEN TD010*@JJAmount/([email protected])  ELSE TD010*@JJAmount END)  AS TH045,
(CASE @TG010 WHEN '1' THEN TD010*@JJAmount/([email protected])*@TG030  when '2' then TD010*@JJAmount*@TG030 else 0 END)  AS TH046,
(CASE @TG010 WHEN '1' THEN TD010*@JJAmount/([email protected])  ELSE TD010*@JJAmount END) *@TG008 as TH047 ,
(CASE @TG010 WHEN '1' THEN TD010*@JJAmount/([email protected])*@TG030  when '2' then TD010*@JJAmount*@TG030 else 0 END) *@TG008 AS TH048,
@boxAmount,@boxAmount1,@boxBackAmount,0,TD032,0,0,'','',0,0,0 AS TH060,0,0,'',TD038,TD009,'','',0,0,'N',1,'##########','','','','',0,0,0,'N' AS TH080,
0,'2','','','','0001','0001','','','','','',TD201,0,0,0,0,0,0,'','','','','','',0,0,0,0,0,0 FROM 
EGP..PURTD WHERE [email protected] AND [email protected] AND [email protected]
  ----直接進行插入檢驗單頭檔
           INSERT EGP..QMSTA
           SELECT  'EGP',@TA006,@MF004,@YScreatedate,'','',1,@TG001,@TG002,RIGHT('0000'+RTRIM(CAST(@XH AS CHAR(4))),4) AS TH003,@TG003,@TG003,@TA006,0,
           0,0,'','2','4',0,'Y' AS TA014,'','','','',@TG003,@TA006,'N',0,0,0,0,'0001','允收',1,@TG003,'',0,0,0,'N' AS TA034,'','','','','','',0 AS TA041,0,0,0,0 AS TA045,0,0,0,'' as TAC04,0,'',0,0,0,'','','','',TD021,TD201,0,0,0,0,0,0,
           '','','','','','',0,0,0,0,0,0 FROM EGP..PURTD WHERE [email protected] AND [email protected] AND [email protected]


END


UPDATE barcode_PURTC 
SET barcode_PURTC.status='1' 
from barcode_PURTC, barcode_PURTD
WHERE barcode_PURTC.id = barcode_PURTD.billid and [email protected] AND 
[email protected] AND [email protected] and barcode_PURTC.optcode = @optcode and
barcode_PURTC.status = '0' 


--UPDATE barcode_PURTC SET status='Y' WHERE [email protected] AND [email protected] AND 


SELECT @[email protected]+1
FETCH NEXT FROM MYDETAILCURSOR INTO
@TD001,@TD002,@TD003,@amount,@amount1,@boxAmount1,@backAmount,@boxBackAmount,@JJAmount,@amountpk,@amountgk
END
CLOSE MYDETAILCURSOR
DEALLOCATE MYDETAILCURSOR
update barcode_PURTC SET status='1' WHERE status='0' AND [email protected] AND [email protected] AND [email protected] AND [email protected] AND [email protected] AND [email protected] 
---進行迴圈單身插入-
--進行更新單尾合計資訊  進貨金額,原幣稅額,總驗收數量,原幣貨款金額,本幣貨款金額,本幣稅額,總驗收包裝量,總進貨數量,總進貨包裝量
UPDATE EGP..PURTG SET TG017=(SELECT SUM(TH019) FROM  EGP..PURTH WHERE TG001=TH001 AND TG002=TH002 AND [email protected] AND [email protected]) , 
TG019=(SELECT SUM(TH046) FROM  EGP..PURTH WHERE TG001=TH001 AND TG002=TH002 AND [email protected] AND [email protected]) ,
TG026=(SELECT SUM(TH015)  FROM  EGP..PURTH WHERE TG001=TH001 AND TG002=TH002 AND [email protected] AND [email protected]) ,
TG028=(SELECT SUM(TH045)  FROM  EGP..PURTH WHERE TG001=TH001 AND TG002=TH002 AND [email protected] AND [email protected]
,TG031=(SELECT SUM(TH047)  FROM  EGP..PURTH WHERE TG001=TH001 AND TG002=TH002 AND [email protected] AND [email protected]) ,
TG032=(SELECT SUM(TH048) FROM  EGP..PURTH WHERE TG001=TH001 AND TG002=TH002 AND [email protected] AND [email protected]
,TG040=(SELECT SUM(TH050)  FROM  EGP..PURTH WHERE TG001=TH001 AND TG002=TH002 AND [email protected] AND [email protected]) ,
TG053=(SELECT SUM(TH007)  FROM  EGP..PURTH WHERE TG001=TH001 AND TG002=TH002 AND [email protected] AND [email protected]
,TG054=(SELECT SUM(TH049)  FROM  EGP..PURTH WHERE TG001=TH001 AND TG002=TH002 AND [email protected] AND [email protected]
WHERE [email protected] AND [email protected]
--更新到貨單
--UPDATE EGP..PURCD SET CD018=(SELECT SUM(TH015) FROM EGP..PURTH WHERE CD001=THC03 AND CD002=THC04 AND CD003=THC05) WHERE [email protected] AND [email protected]
--UPDATE EGP..PURCC SET CC013=(SELECT SUM(CD008) FROM EGP..PURCD WHERE CD001=CC001 AND CD002=CC002) WHERE [email protected] AND [email protected]
FETCH NEXT FROM MYCURSOR INTO
@TG005,@TC001,@TC002
END
CLOSE MYCURSOR
DEALLOCATE MYCURSOR




commit transaction








GO



相關推薦

條碼系統儲存過程 示例

這個是sql sever的儲存過程,以後要改成oracle的 手持式條碼機批量掃描條碼後,無線上傳到伺服器,伺服器後臺通過儲存過程自動生產對應的資料。 USE [Barcode] GO /****** Object:  StoredProcedure [dbo].[ds_

mysql 儲存過程示例

在mysql的test庫中執行如下sql: -- ---------------------------- -- Table structure for user -- ---------------------------- DROP TABLE IF EXISTS `user`; CREAT

SQL SERVER常用系統儲存過程

--獲得MS SQL的版本號 execute master..sp_msgetversion --得到硬碟檔案資訊 --引數說明:目錄名,目錄深度,是否顯示檔案 execute master..xp_dirtree 'c:' execute master..xp_dirtr

PL/SQL儲存過程示例及圖解

這幾天專案任務中需要建立一個儲存過程介面,以方便後續的呼叫,由於之前沒怎麼在Oracle PL/SQL中新建過儲存過程,所以花了些時間去看,結果發現通過百度到的都是些儲存過程的知識而非PL/SQL中的新建-檢視結果的過程。所以決定寫一篇圖文結合的文章來講述PL/

通過系統儲存過程手動執行SQL Server中的Job

目錄 系統儲存過程sp_start_job 在SQL Server中,若想通過T-SQL指令碼手動執行SQL Server Agent中的Job(作業任務),則可使用系統儲存過程sp_star

Sql Server 常用系統儲存過程大全

EXEC xp_cmdshell --*執行DOS各種命令,結果以文字行返回。 EXEC xp_fixeddrives --*查詢各磁碟/分割槽可用空間 EXEC xp_loginconfig --*報告SQL Server 例項在Windows 上執行時的登入安全配置

SQL2000系統表、儲存過程、函式的功能介紹及應用2009年01月21日 星期三 11:38雖然使用系統儲存過程系統函式與資訊架構檢視已經可以為我們提供了相當豐富的元資料資訊,但是對於某些特殊的元資料資訊,我們仍然需要直接對系統表進行查詢。因為SQL

雖然使用系統儲存過程、系統函式與資訊架構檢視已經可以為我們提供了相當豐富的元資料資訊,但是對於某些特殊的元資料資訊,我們仍然需要直接對系統表進行查詢。因為SQL Server 將所有資料庫物件的資訊均存放在系統表中,作為 SQL Server 的管理、開發人員,瞭解各個系統表的作用將有助於我們瞭解 SQL

postgresql 9.4儲存過程示例

create or replace function product_analyze_day_stat(p_stat_day timestamp) returns void as $$ /** *貨品分析日報表 */ declare v_db_info varchar(1

幾個SQL server登陸,登入,使用者,角色和組用到的系統儲存過程

登入、使用者、角色和組是 Microsoft® SQL Server™ 2000 安全機制的基礎。連線到 SQL Server 的使用者必須使用特定的登入識別符號 (ID) 標識自己。因此,使用者只能檢視經授權可以檢視的表和檢視,並且只能執行經授權可以執行的儲存過程和管理功能。這一安全系統基於用來標識使用者

用於檢視配置的儲存過程 | 全方位認識 sys 系統

在上一篇《用於修改配置的儲存過程 | 全方位認識 sys 系統庫》中,我們介紹了sys 系統庫中用於修改配置的儲存過程,利用這些儲存過程可以代替修改performance_schema配置表的DML語句等操作,本期的內容講介紹用於檢視performance_schema配置資訊的儲存過程。 PS

執行儲存過程時,返回引數示例程式碼

//引數 SqlParameter[] fparams = new SqlParameter[7]; fparams[0] = new SqlParameter("@ID", ID); fparams[

資料庫系統概論05-動態SQL&儲存過程&函式

動態SQL 使用SQL語句主變數 EXEC SQL BEGIN DECLARE SECTION; const char *stmt="CREATE TABLE test(a int);"/*SQL語句主變數,內容是建立表的SQL語句*/ EXEC SQL END DECLARE SE

Linux CENTOS7 Linux ntopng流量監控、埠監控、服務監控管理系統 安裝過程以及示例!另外附帶CENTOS6的安裝過程

centos 7 安裝ntopng 1、新增ntopng官方yum源 cd /etc/yum.repos.d/ wget http://packages.ntop.org/centos/ntop.repo -O ntop.repo 2、centos新增epel 7 yum

牛腩新聞釋出系統 (三)走進儲存過程

什麼是儲存過程 我第一次運用儲存過程是在機房重構時,在進行組合查詢設計時我需要通過多條sql語句查詢資訊,欄位和屬性,我把sql語句寫在了資料庫的“儲存過程”中,而在程式中只需要呼叫儲存過程,就可以執行查詢語句的功能了。下面是我組合查詢的儲存過程展示 USE [Engine

資料庫系統學習筆記--函式和儲存過程

目錄   函式 自定義函式 基本語法 控制語句 儲存過程 自定義函式和儲存過程的區別 函式 函式的意義就在於完成特定的功能,寫一份函式,可以在多個語句中多次使用,簡化程式設計工作。 資料庫系統中的函式大致也可以分為內建函式和自定義函式(UDF

資料庫系統概論05-動態SQL&儲存過程&函式

動態SQL 使用SQL語句主變數 EXEC SQL BEGIN DECLARE SECTION; const char *stmt="CREATE TABLE test(a int);"/*SQL語句主變數,內容是建立表的SQL語句*/ EXEC SQL END

mybatis 呼叫oracle儲存過程,傳參、返回遊標的值獲取--示例

1,dao層程式碼 Integer currentlq_fsx = getSqlSession().selectOne("lqMapper.maxscore"); Map<String,Object> map = new HashMap<String,O

oracle簡單的儲存過程以及job示例

最近需要oracle迴圈定時執行一段sql語句,然後需要建立儲存過程,本人的sql語句屬於DML語句,步驟如下: 1、建立儲存過程 create or replace procedure cube_day as begin insert into prov_day_wea

sqlserver儲存過程中利用遊標遍歷結果集簡單示例及查詢資料庫時間

本例項用的是sqlserver2005   在儲存過程中遍歷結果,和查詢資料庫中所有 儲存過程名稱 加以處理以文字形式輸出 原始碼: drop procedure findName create procedure findName--建立一個名為findName的儲存過

mysql:使用者變數、系統變數、區域性變數(儲存過程中的)

MySQL資料庫中的變數分為MySQL系統變數和MySQL使用者變數。 一、MySQL使用者變數:基於會話變數實現的, 可以暫存值, 並傳遞給同一連線裡的下一條sql使用的變數.當客戶端連線退出時,變