This query below is running but I would like to add this extra condition; run this query only if there is data in the table STAGE.LAB.DATA.
I tried CASE and IF THEN, but I can’t get it to work. Please help. What syntax should be added? Thanks
SELECT *
FROM
( SELECT EXISTS ( SELECT 1 FROM STAGE.LAB.DATA A
WHERE (A.HOT_TEMP_VALUE >= 118 AND A.HOT_TEMP_VALUE <= 122) ) AS result)
WHERE RESULT !='TRUE';
IF
SELECT COUNT(*) FROM STAGE.LAB.DATA >1
THEN
SELECT *
FROM
( SELECT EXISTS ( SELECT 1 FROM STAGE.LAB.DATA A
WHERE (A.HOT_TEMP_VALUE >= 118 AND A.HOT_TEMP_VALUE <= 122) ) AS result)
WHERE RESULT !='TRUE';
ELSE
END IF
2
Answers
In order to use a query result as a value, you have to put it in parentheses:
IF
statements can only be used in stored programs. In an ordinary query, you can useWHERE
clause:This will return an empty result if there’s nothing in
STAGE.LAB.DATA
.EXISTS stops table scanning after first matched row is found. Rather than COUNT()..