SELECT
  [EmpTemplateHistoryID],
  [EmployeeID],
  [TemplateID],
  [AdjustStatus],
  [AdjustReason],
  [AdjustTime],
  isnull((select top 1 [EmpTemplateHistoryID] from [EmpPRTemplateHistory] where [EmployeeID]=a.EmployeeID),NEWID()) [AdjustBeforeHistoryID],
  [Remark],
  getdate()
 FROM @DataTable a
 where NOT EXISTS
  (SELECT * FROM [EmpPRTemplateHistory] WHERE
   [EmployeeID] = a.[EmployeeID]
    AND TemplateID = a.TemplateID
   AND AdjustReason=a.AdjustReason
   )
posted on 2012-06-15 15:27  万德源  阅读(236)  评论(0编辑  收藏  举报