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

Popular posts from this blog

50 Essential SQL Questions to Land Your Dream Job

How to find all the customers who placed orders on three consecutive days | SQL Scenario questions

ACCENTURE SQL INTERVIEW QUESTION | Change the ProductIDs