How can I convert the following T-SQL construct to SQL-PL?
if @ParameterType not in ('p1', 'p2', 'p3', 'p4', 'p4', 'p5')
begin
print 'good parameter'
end
else
begin
print 'bad parameter'
end
I want to avoid using a nested if...then....elseif..., if possible. I
am newbie to DB2 UDB.
Brian Tkatch - 28 Mar 2006 23:10 GMT
CASE should work fine.
CASE Parameter_Type
WHEN NOT IN 'p1', 'p2', 'p3', 'p4', 'p4', 'p5') THEN 'Good
Parameter'
ELSE 'Bad Parameter'
END
In a sample FUNCTION:
CREATE FUNCTION A (Parameter_Type VARCHAR(2))
RETURNS VARCHAR(15)
RETURN
CASE Parameter_Type
WHEN NOT IN 'p1', 'p2', 'p3', 'p4', 'p4', 'p5') THEN 'Good
Parameter'
ELSE 'Bad Parameter'
END
VALUES A('p1')
VALUES A('qq')
B
Serge Rielau - 29 Mar 2006 02:09 GMT
> CASE should work fine.
>
[quoted text clipped - 17 lines]
> VALUES A('p1')
> VALUES A('qq')
.. and DB2 supports:
IF THEN ELSEIF /* <-- no space ! */ END IF

Signature
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab