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} 

}

  • 0
  • 0
  • 131
  • 1
  • 1

Answers

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

Comments