Question
· Feb 14, 2019

HOW TO USE CONDITIONAL LOGIC IN SQL

Is there a way or can it be done to use conditional logic in sql like so

    

 Query Q1(formal as %String) As %SQLQuery [ Final ]
{
    
    SELECT patientnumber,ID, CASE
    WHEN ID = 50 THEN "The is 50"
    WHEN ID = 30 THEN "This is 30"
    ELSE "The quantity is under 30"
END FROM Audit.Table WHERE ID = :formal AND EndDate is null} 

}

Discussion (2)2
Log in or sign up to continue

Try using single quotes in your SQL query and also defining your column name:

 Query Q1(formal as %String) As %SQLQuery [ Final ]
{
    SELECT patientnumber, ID, 
    CASE
    WHEN ID = 50 THEN 'The is 50'
    WHEN ID = 30 THEN 'This is 30'
    ELSE 'The quantity is under 30'
    END
    As myValue 
    FROM Audit.Table WHERE ID = :formal AND EndDate is null