Advertisement
EvgenyRudenko

sert 2023

Jan 11th, 2023
2,976
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 4.92 KB | None | 0 0
  1.  --- выполняем на srv-sql03
  2.  --- на srv-sql01 нет нужных записей в sys.servers
  3.  
  4.  DECLARE @Order_Id BIGINT
  5. SET @Order_Id= 126917773
  6. DECLARE @CheckUID VARCHAR(36)
  7. SET @CheckUID = (SELECT CheckUID FROM [SRV-SQL01].sms_union.dbo.Prepaid WHERE Order_Id=@Order_Id AND Summ_Prepaid<0)
  8.  
  9.  DECLARE @number_cert TABLE
  10. (
  11.     CashId INT,
  12.     CashCheckNo INT,
  13.     number_cert BIGINT,
  14.     id_type_coupon UNIQUEIDENTIFIER,
  15.     Sum_coupon INT
  16.    
  17. )
  18.  
  19.  DECLARE  @CashID INT
  20.  SET @CashID = (SELECT DISTINCT  cm.CashID  from Loyalty.dbo.Coupon_move as cm with(nolock) where  cm.CashCheckNo =  @Order_Id)
  21.  DECLARE @CashCheckNo INT
  22.  SET @CashCheckNo = (SELECT TOP 1 cm.CashCheckNo  from Loyalty.dbo.Coupon_move as cm with(nolock) where  cm.CashCheckNo = @Order_Id)
  23.  DECLARE @Close_Date DATETIME
  24.  SET @Close_Date = (SELECT TOP 1  Close_Date FROM [SRV-SQL01].sms_union.dbo.Prepaid WHERE Order_Id = @Order_Id AND Summ_Prepaid >0)
  25.  
  26. INSERT INTO @number_cert
  27. (
  28.     CashId,
  29.     CashCheckNo,
  30.     number_cert,
  31.     id_type_coupon,
  32.     Sum_coupon
  33. )
  34. SELECT cm.CashID, cm.CashCheckNo,cm.number_cert, cm.id_type_coupon, tcl.Sum_coupon
  35. FROM Loyalty.dbo.Coupon_move cm
  36. INNER JOIN [SRV-SQL03].OnlinePay.[dbo].[Types_coupon_loyalty] tcl ON tcl.id_type_coupon = cm.id_type_coupon
  37. WHERE CashCheckNo = @Order_Id
  38. SELECT * FROM @number_cert
  39.  
  40.  
  41. --- то что нужно вставить. Разбиваем на строки по сертификатам отдельно
  42. -- 3
  43. INSERT INTO [SRV-SQL01].SMS_UNION.dbo.Prepaid
  44. (
  45.     Prepaid_Id,
  46.     Summ_Prepaid,
  47.     Order_Id,
  48.     Number_Cert,
  49.     Cashid,
  50.     Cash_Check_No,
  51.     Close_Date,
  52.     CheckUID,
  53.     Date_Add,
  54.     Fisc_No,
  55.     terminal,
  56.     Shift_No,
  57.     order_type,
  58.     pay_type,
  59.     is_fisc_corrected,
  60.     fr_fisc_id,
  61.     fr_check_id,
  62.     _uid,
  63.     _date_fix,
  64.     _date_correction_prepared,
  65.     _date_correction_completed,
  66.     _fr_fisc_id,
  67.     _fr_check_id,
  68.     _c_num,
  69.     type_insert,
  70.     Summ_Prepaid_old,
  71.     Sum_VatNo,
  72.     Sum_Vat10,
  73.     Sum_Vat20,
  74.     id_kontr,
  75.     id_contract_type,
  76.     PayUID,
  77.     FiscDate
  78. )
  79. SELECT
  80.     1,       -- Prepaid_Id - int
  81.     [@number_cert].Sum_coupon,    -- Summ_Prepaid - decimal(15, 2)
  82.     a.Order_Id, -- Order_Id - bigint
  83.     [@number_cert].number_cert, -- Number_Cert - bigint
  84.     25191, -- Cashid - bigint
  85.     a.Cash_Check_No, -- Cash_Check_No - int
  86.     a.Close_Date,    -- Close_Date - datetime
  87.     NULL,    -- CheckUID - varchar(36)
  88.     a.Date_Add, -- Date_Add - datetime
  89.     a.Fisc_No, -- Fisc_No - bigint
  90.     a.terminal, -- terminal - varchar(20)
  91.     a.Shift_No, -- Shift_No - int
  92.     a.order_type, -- order_type - tinyint
  93.     a.pay_type, -- pay_type - tinyint
  94.     a.is_fisc_corrected,    -- is_fisc_corrected - tinyint
  95.     a.fr_fisc_id,    -- fr_fisc_id - int
  96.     a.fr_check_id,    -- fr_check_id - int
  97.     NULL,    -- _uid - uniqueidentifier
  98.     NULL,    -- _date_fix - datetime
  99.     NULL,    -- _date_correction_prepared - datetime
  100.     NULL,    -- _date_correction_completed - datetime
  101.     NULL,    -- _fr_fisc_id - bigint
  102.     NULL,    -- _fr_check_id - int
  103.     NULL,    -- _c_num - varchar(36)
  104.     NULL,    -- type_insert - tinyint
  105.     NULL,    -- Summ_Prepaid_old - decimal(15, 2)
  106.     0,    -- Sum_VatNo - decimal(15, 2)
  107.     0,    -- Sum_Vat10 - decimal(15, 2)
  108.     [@number_cert].Sum_coupon,    -- Sum_Vat20 - decimal(15, 2)
  109.     a.id_kontr,    -- id_kontr - int
  110.     a.id_contract_type,    -- id_contract_type - tinyint
  111.     NEWID(),    -- PayUID - uniqueidentifier ---- уникальный один и тот же не получится
  112.     a.FiscDate     -- FiscDate - datetime
  113.     FROM @number_cert, (
  114. SELECT * FROM [SRV-SQL01].SMS_UNION.dbo.Prepaid WHERE Order_Id = @Order_Id AND Summ_Prepaid>0 --@Order_Id
  115. ) a
  116.  
  117.  
  118.  
  119. /*
  120. DELETE FROM [SRV-SQL01-QA].SMS_UNION.dbo.Prepaid
  121. WHERE Order_Id = 126917773 AND Summ_Prepaid>0 AND Prepaid_Id=1 --@Order_Id
  122. */
  123. --  4.  сводных отчетов бухгалтерии формируется таблице Check_GiftCard
  124. SELECT TOP (10)* FROM [SRV-SQL01].SMS_REPL.dbo.Check_GiftCard g WITH (NOLOCK)
  125.  
  126.  
  127. --  SELECT  * FROM [SRV-SQL01-QA].SMS_UNION.dbo.Prepaid WHERE Order_Id = 126917773 AND Summ_Prepaid>0 --@Order_Id
  128.  
  129. --   SELECT 'Loyalty.dbo.Coupon_move',* FROM Loyalty.dbo.Coupon_move as cm with(nolock) WHERE  cm.CashCheckNo = 126917773
  130.  
  131. --  SELECT 'Loyalty.dbo.Coupon_move',* FROM Loyalty.dbo.Coupon_move as cm with(nolock) WHERE  cm.CashCheckNo = @Order_Id
  132.  
  133. INSERT INTO [SRV-SQL01].SMS_REPL.dbo.Check_GiftCard
  134. (
  135.     CheckUID,
  136.     number_cert,
  137.     CashID,
  138.     CashCheckNo,
  139.     Closedate,
  140.     date_add,
  141.     operation_type,
  142.     Type_sale,
  143.     BONUSCARD
  144. )
  145. SELECT id_type_coupon, number_cert, 25191 AS CashId, CashCheckNo, GETDATE() AS Closedate, GETDATE() AS date_add , 1 AS operation_type , 1 AS type_sale, NULL AS BONUSCARD FROM @number_cert
  146.  
  147. -- 5.
  148. DELETE FROM [SRV-SQL01].SMS_UNION.dbo.Prepaid
  149. WHERE Prepaid_Id =3 AND Order_Id=@Order_Id
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement