批量處理的sql語句

來源:互聯網
上載者:User

  declare @EmpTemplateHistoryIDS nvarchar(max)='86e83923-47ac-4541-a124-c1136a0b5fa6';
     declare @TablePayrollFixedItemHistory table
  (
  EmployeeID nvarchar(50),
  EmptemplateHistoryID  nvarchar(50),
  ItemID  nvarchar(50),
  ItemName  nvarchar(50),
  OldItemValue  nvarchar(50),
  NewItemValue  nvarchar(50),
  CreateTime datetime,
  LastUpdateTime datetime
  )
  ---把要儲存的固定項曆史儲存到暫存資料表
  insert into @TablePayrollFixedItemHistory
     select b.EmployeeID,a.*
        from
        [PayrollFixedItemHistory] a,EmpPRTemplateHistory b
       
        where a.EmpTemplateHistoryID=b.EmpTemplateHistoryID and a.EmpTemplateHistoryID
        in (select value from UFun_SqlSplit(@EmpTemplateHistoryIDS,','))
       
        select * from @TablePayrollFixedItemHistory
       
        delete   a   from PayrollFixedItem a , @TablePayrollFixedItemHistory b
        where a.EmployeeID=b.EmployeeID  and a.ItemID not in(select ItemID from @TablePayrollFixedItemHistory where EmployeeID=a.EmployeeID)

    UPDATE a SET
  [ItemValue] = b.[NewItemValue],
  [LastUpdateTime] = getdate()
 FROM [PayrollFixedItem] a, @TablePayrollFixedItemHistory b
 WHERE
  a.[EmployeeID] = b.[EmployeeID] AND
  a.[ItemID] = b.[ItemID]
  
 INSERT INTO [PayrollFixedItem]
 (
  [EmployeeID],
  [ItemID],
  [ItemValue],
  [CreateTime]
 )
 SELECT
  [EmployeeID],
  [ItemID],
  [NewItemValue],
  getdate()
 FROM @TablePayrollFixedItemHistory a
 WHERE NOT EXISTS
  (SELECT * FROM [PayrollFixedItem] WHERE
   [EmployeeID] = a.[EmployeeID] AND
   [ItemID] = a.[ItemID])

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.