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
Comments
Maybe this is not the best answer, but there are detailed explanation with examples of conditional sql here: https://www.geeksforgeeks.org/sql-conditional-expressions/
I hope this helps,
Thanks,
Alex
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
}