By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,226 Members | 1,027 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,226 IT Pros & Developers. It's quick & easy.

SQL construct conversion...

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.