Process logs condition setup using SQL | SQL Interview question
Logic:
If all steps of a workflow are of the same status (Error, Complete, or Running), then return the
distinct status.
If any steps of a workflow have an Error status along with a status of Complete or Running, set
the overall status to Indeterminate.
If the workflow steps have a combination of Complete and Running (without any Errors), set the
overall status to Running.
DML Script:
DROP TABLE IF EXISTS ProcessLog;
GO
CREATE TABLE ProcessLog
(
Workflow VARCHAR(100),
StepNumber INTEGER,
RunStatus VARCHAR(100) NOT NULL
);
GO
INSERT INTO ProcessLog (Workflow, StepNumber, RunStatus) VALUES
('Alpha',1,'Error'),('Alpha',2,'Complete'),('Alpha',3,'Running'),
('Bravo',1,'Complete'),('Bravo',2,'Complete'),
('Charlie',1,'Running'),('Charlie',2,'Running'),
('Delta',1,'Error'),('Delta',2,'Error'),
('Echo',1,'Running'),('Echo',2,'Complete'),
('Beta',1,'Error'),('Beta',2,'Complete') ;
GO
Comments
Post a Comment