Hello …
I am trying to understand how to use the IF statement in my SELECT statement.
I will be unioning three queries together, each are pretty much the same but the WHERE clauses have a few differences. The type of data I am querying may identify both “error” and “warning” message types. The business rule is if the message type is equal to ERROR, then do not display the warning messages.
Here is the first query from my union:
The IBM SQL Reference guide provides an example of the IF statement, which I think is what I want, but I’m not sure how to implement this in my syntax and am I only able to update values or can I delete entire records?
Thanks in advance!
I am trying to understand how to use the IF statement in my SELECT statement.
I will be unioning three queries together, each are pretty much the same but the WHERE clauses have a few differences. The type of data I am querying may identify both “error” and “warning” message types. The business rule is if the message type is equal to ERROR, then do not display the warning messages.
Here is the first query from my union:
Code:
SELECT P.USER_CD,
'ERRORS' AS TYPE,
COUNT(*) AS TOTAL
FROM SYS4.VLR_PACK P,
SYS4.VLR_EDIT_ERR E,
SYS4.VLR_EDIT_MSG M1,
SYS4.VLR_EDIT_MSG M2,
SYS4.VLR_USER R
WHERE E.RECORD_NUM_A = P.RECORD_NUM
AND E.MSG_ID_1 = M1.MSG_ID
AND E.MSG_ID_2 IS NOT NULL
AND E.MSG_ID_2 = M2.MSG_ID
AND M1.MSG_TP <> 'E'
AND M2.MSG_TP = 'E'
AND P.USER_CD = R.USER_NUM
The IBM SQL Reference guide provides an example of the IF statement, which I think is what I want, but I’m not sure how to implement this in my syntax and am I only able to update values or can I delete entire records?
Code:
IF rating = 1
THEN SET new_salary =
new_salary + (new_salary * .10);
ELSEIF rating = 2
THEN SET new_salary =
new_salary + (new_salary * .05);
ELSE SET new_salary =
new_salary + (new_salary * .02);
END IF
Thanks in advance!