Sql server 脚本以查找在过去1小时内更新的行数

Sql server 脚本以查找在过去1小时内更新的行数,sql-server,tsql,Sql Server,Tsql,该脚本确实提供了更改行的列表,但我还需要确保更改行的数量应等于在过去1小时内更新的行的数量,这将使我在验证时更加放心 下面是代码,它给出了更改行的列表。如果我没有错的话,Exception会给出第一个select语句中不在第二个select语句中的所有行。我只是想知道,当我运行下面的查询时,如何检查上一个hr中更新的行数,这些行数必须与行数匹配 Select [Accounting_Period_ID] ,[Policy_Number] ,[Risk_ID] ,[Product_

该脚本确实提供了更改行的列表,但我还需要确保更改行的数量应等于在过去1小时内更新的行的数量,这将使我在验证时更加放心

下面是代码,它给出了更改行的列表。如果我没有错的话,Exception会给出第一个select语句中不在第二个select语句中的所有行。我只是想知道,当我运行下面的查询时,如何检查上一个hr中更新的行数,这些行数必须与行数匹配

  Select [Accounting_Period_ID]
  ,[Policy_Number]
  ,[Risk_ID]
  ,[Product_ID]
  ,[Inception_Date_ID]
  ,[Effective_Date_ID]
  ,[Expiration_Date_ID]
  ,[Cancellation_Date_ID]
  ,[Reinstate_Date_ID]
  ,[Policy_Source_System_ID]
  ,[Risk_Geo_ID]
  ,[Risk_Profile_ID]
  ,[Policy_Status_ID]
  ,[Agency_ID]
  ,[Limit_Selection_ID]
  ,[Written_Premium_MTD]
  ,[Written_Premium_ITD]
  ,[Fees_MTD]
  ,[Fees_ITD]
  ,[Commission_MTD]
  ,[Commission_ITD]
  ,[Earned_Premium_MTD]
  ,[Earned_Premium_ITD]
  ,[In_Force_Count]
  ,[New_Business_Count]
  ,[Renewed_Count]
  ,[Cancelled_Count]
  ,[Reinstated_Count]
  ,[Dwelling_Limit]
  ,[Other_Structures_Base_Limit]
  ,[Other_Structures_Extended_Limit]
  ,[Other_Structures_Total_Limit]
  ,[Contents_Limit]
  ,[Additional_Living_Expense_Limit]
  ,[Liability_Limit]
  ,[Medical_Limit]
  ,[Total_Insured_Value]
  ,[Replacement_Value]
  ,[AOP_Deductible]
  ,[Days_in_Force]
  ,[Earned_House_Years]
  ,[Cancellation_Entry_Date_ID]
  ,[Reinstate_Entry_Date_ID]
  ,[Seq]
  ,[Inserted_Date]
  ,[Inserted_By]
  ,[Last_Updated_Date]
  ,[Last_Updated_By]
  ,[Insurance_score]
  ,[Rewrite_Count]
  ,[Entry_Date_ID] from Datamart.Policy.Fact_Monthly_Policy_Snap_20190403 
where Policy_Source_System_ID = 8
EXCEPT
Select [Accounting_Period_ID]
  ,[Policy_Number]
  ,[Risk_ID]
  ,[Product_ID]
  ,[Inception_Date_ID]
  ,[Effective_Date_ID]
  ,[Expiration_Date_ID]
  ,[Cancellation_Date_ID]
  ,[Reinstate_Date_ID]
  ,[Policy_Source_System_ID]
  ,[Risk_Geo_ID]
  ,[Risk_Profile_ID]
  ,[Policy_Status_ID]
  ,[Agency_ID]
  ,[Limit_Selection_ID]
  ,[Written_Premium_MTD]
  ,[Written_Premium_ITD]
  ,[Fees_MTD]
  ,[Fees_ITD]
  ,[Commission_MTD]
  ,[Commission_ITD]
  ,[Earned_Premium_MTD]
  ,[Earned_Premium_ITD]
  ,[In_Force_Count]
  ,[New_Business_Count]
  ,[Renewed_Count]
  ,[Cancelled_Count]
  ,[Reinstated_Count]
  ,[Dwelling_Limit]
  ,[Other_Structures_Base_Limit]
  ,[Other_Structures_Extended_Limit]
  ,[Other_Structures_Total_Limit]
  ,[Contents_Limit]
  ,[Additional_Living_Expense_Limit]
  ,[Liability_Limit]
  ,[Medical_Limit]
  ,[Total_Insured_Value]
  ,[Replacement_Value]
  ,[AOP_Deductible]
  ,[Days_in_Force]
  ,[Earned_House_Years]
  ,[Cancellation_Entry_Date_ID]
  ,[Reinstate_Entry_Date_ID]
  ,[Seq]
  ,[Inserted_Date]
  ,[Inserted_By]
  ,[Last_Updated_Date]
  ,[Last_Updated_By]
  ,[Insurance_score]
  ,ISNULL([Rewrite_Count],0) Rew
  ,[Entry_Date_ID] from Datamart.Policy.Fact_Monthly_Policy_Snap
   where Policy_Source_System_ID = 8
DATEADD(hh,-1,GETDATE())为您提供实际时间减去1小时。您可以将其与上次更新的日期进行比较。
Count(*)给出了行数。

这些论坛上的人怎么会知道这一点?你在任何地方跟踪记录日期吗?谢谢!让我试试这个。