You are only showing us rows 888 and 889 in the result set. Apparently the same combo of ADMIN_AUDIT.job_nbr, ADMIN_AUDIT.process_txt, ADMIN_AUDIT.sub_process_txt, sp_id ran around 2022-03-29 04:16 as well.
Incorrect query result - SQL Server 2016
I'm seeing incorrect result returned by a query I just ran this morning in production (I ran the same query last night couple of times).
Here is the query:
SELECT DATEDIFF(minute, LAG(ADMIN_AUDIT.admin_audit_dttm)
OVER (PARTITION BY ADMIN_AUDIT.job_nbr, ADMIN_AUDIT.process_txt, ADMIN_AUDIT.sub_process_txt, sp_id ORDER BY ADMIN_AUDIT.admin_audit_dttm, ADMIN_AUDIT.admin_audit_id), ADMIN_AUDIT.admin_audit_dttm)
AS [StepTime (min.)], * FROM dbo.ADMIN_AUDIT
WHERE ADMIN_AUDIT.admin_audit_dttm > '20220329'
AND ADMIN_AUDIT.sub_process_txt = 'usp_Load_MED_CLAIM_PROF'
ORDER BY ADMIN_AUDIT.admin_audit_dttm, ADMIN_AUDIT.admin_audit_id, sp_id
I'm examining the first column to see which step of the procedure takes longest time (I already identified it, now need to figure out how to improve that particular query). Anyway, this is the result:
The sp_id is different in these two rows (these are two different processes). Why would I get the incorrect result in that query (the other similar stop/start return NULL correctly in the first column)?
Thanks in advance.
Developer technologies | Transact-SQL
SQL Server | Other
-
Erland Sommarskog 128.7K Reputation points MVP Volunteer Moderator2022-03-30T21:47:18.877+00:00