467,189 Members | 1,318 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,189 developers. It's quick & easy.

SQL construct conversion...

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.

Mar 28 '06 #1
  • viewed: 1293
Share:
2 Replies
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

Mar 28 '06 #2
Brian Tkatch wrote:
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')

... and DB2 supports:
IF THEN ELSEIF /* <-- no space ! */ END IF

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Mar 29 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Mac | last post: by
1 post views Thread by Stub | last post: by
11 posts views Thread by Steve Gough | last post: by
2 posts views Thread by Ninan | last post: by
4 posts views Thread by spibou@gmail.com | last post: by
4 posts views Thread by joe | last post: by
1 post views Thread by Nikhil.S.Ketkar@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.