sql 在Audit Detail.sql中将Redalerts Y转换为N,将N转换为Y.

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 在Audit Detail.sql中将Redalerts Y转换为N,将N转换为Y.相关的知识,希望对你有一定的参考价值。

DECLARE @tblYesRecords TABLE (
	Id BIGINT
	,Answer NVARCHAR(10)
	)
DECLARE @tblNoRecords TABLE (
	Id BIGINT
	,Answer NVARCHAR(10)
	)

INSERT INTO @tblYesRecords (
	Id
	,Answer
	)
SELECT ad.Id
	,ad.Answer
FROM dbo.AuditDetail ad
INNER JOIN dbo.QuestionMaster qm ON ad.QuestionId = qm.Id
	AND qm.IsRedAlerts = 1
INNER JOIN dbo.Audit a ON ad.AuditId = a.Id
	AND a.CreatedDate < '2017-03-22 17:00:00.000'
WHERE UPPER(ltrim(rtrim(ad.Answer))) = 'Y'
ORDER BY a.Id --185

INSERT INTO @tblNoRecords (
	Id
	,Answer
	)
SELECT ad.Id
	,ad.Answer
FROM dbo.AuditDetail ad
INNER JOIN dbo.QuestionMaster qm ON ad.QuestionId = qm.Id
	AND qm.IsRedAlerts = 1
INNER JOIN dbo.Audit a ON ad.AuditId = a.Id
	AND a.CreatedDate < '2017-03-22 17:00:00.000'
WHERE UPPER(ltrim(rtrim(ad.Answer))) = 'N'
ORDER BY a.Id --51849

---------------------------------Yes to No-------------------------------------
UPDATE ad
SET ad.Answer = 'N'
FROM dbo.AuditDetail ad
INNER JOIN @tblYesRecords tyr ON ad.Id = tyr.Id

---------------------------------No to Yes-------------------------------------
UPDATE ad
SET ad.Answer = 'Y'
FROM dbo.AuditDetail ad
INNER JOIN @tblNoRecords tyr ON ad.Id = tyr.Id

以上是关于sql 在Audit Detail.sql中将Redalerts Y转换为N,将N转换为Y.的主要内容,如果未能解决你的问题,请参考以下文章

SQL Server的Audit login与Audit logout

MySQL audit—SQL审计插件

SQL Server Audit记录数据库变更

生产环境audit_trail参数作用和问题

Audit--清理Audit数据

第二十五天 审计 audit