首页 > 解决方案 > 查找过去 1 小时内更新的行数的脚本

问题描述

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

这是给我更改行列表的代码。如果我没记错的话,除了第一个选择语句中不在第二个选择中的所有行之外。我只是想知道如何检查在最后一小时更新的行数,当我在下面运行这个查询时,它必须与行数匹配。

  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

标签: sql-servertsql

解决方案


DATEADD(hh,-1,GETDATE()) 为您提供实际时间减去 1 小时。您可以将其与 Last_Updated_Date 进行比较。Count(*) 为您提供行数。


推荐阅读