我正在尝试从我们的 SQL 日志文件中提取登录成功和失败。这是我能够开始工作的声明,现在运行它时出现错误。任何帮助将不胜感激。我知道它在最后一条语句中,因为其余的在独立运行时可以正常工作。系统没有任何变化,所以我不明白为什么它会开始给出错误?
CREATE TABLE [dbo].[#TmpErrorLog]
([LogDate] DATETIME NULL,
[ProcessInfo] VARCHAR(20) NULL,
[Text] VARCHAR(MAX) NULL);
CREATE TABLE [dbo].[#TmpErrorLog2]
([LogDate] DATETIME NULL,
[ProcessInfo] VARCHAR(20) NULL,
[Text] VARCHAR(MAX) NULL,
[LoginAttempt] VARCHAR(20) NULL);
INSERT INTO #TmpErrorLog ([LogDate], [ProcessInfo], [Text])
EXEC [master].[dbo].[xp_readerrorlog] 0 ;
INSERT INTO #TmpErrorLog2 ([LogDate], [ProcessInfo], [Text], [LoginAttempt])
Select LogDate, ProcessInfo, Replace(Text,'''','"') as Text, SUBSTRING(Text,0,16) as LoginAttempt
From #TmpErrorLog
Where LogDate > GETDATE() - 1 and Text like '%\%'
INSERT INTO LogData ([LogDate], [LoginAttempt], [LoginUser])
Select
LogDate,
Case LoginAttempt When 'Login succeeded' Then 'Successfull' Else 'Failed' End as LoginAttempt,
SUBSTRING(SUBSTRING(Text, CHARINDEX('"', Text,1), CHARINDEX('"', Text, CHARINDEX('"', Text, 0)) - 4),2,50) as LoginUser
From #TmpErrorLog2
Where LogDate Not In(Select LogDate From LogData)
Drop Table #TmpErrorLog
Drop Table #TmpErrorLog2