我有一个每周运行的套餐,但如果计数差异超过1%则需要停止。
这是我的查询以获得2个计数的百分比:
USE MandatedReporting
DECLARE @a AS float
DECLARE @b AS float
declare @c as float
SET @a = ( SELECT Row_Count
FROM [MandatedReporting].[dbo].[DCFS_Weekly_File_Row_Count] WITH(NOLOCK)
WHERE TableName = 'MandatedReporting.dbo.MATCH_WEEKLY_V3'
AND RunDate = ( SELECT MAX(RunDate) AS RunDate
FROM [MandatedReporting].[dbo].[DCFS_Weekly_File_Row_Count] AS ThisWeeksData WITH(NOLOCK)
WHERE TableName = 'MandatedReporting.dbo.MATCH_WEEKLY_V3'))
SET @b = ( SELECT Row_Count
FROM [MandatedReporting].[dbo].[DCFS_Weekly_File_Row_Count] WITH(NOLOCK)
WHERE TableName = 'MandatedReporting.dbo.MATCH_WEEKLY_V3'
AND RunDate = ( SELECT MIN(RunDate) AS RunDate
FROM [MandatedReporting].[dbo].[DCFS_Weekly_File_Row_Count] AS ThisWeeksData WITH(NOLOCK)
WHERE TableName = 'MandatedReporting.dbo.MATCH_WEEKLY_V3'
AND ABS(DATEDIFF(DD,GETDATE(),CAST(RunDate AS DATETIME))) < 10))
set @c = (@a-@b) *100.0/@b SELECT @c as 'Count'
SQL Server 2008 感谢