472,122 Members | 1,463 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,122 software developers and data experts.

Case statement

Hi guys,
I have a doubt regarding the CASE statement. It might sound silly, but me being new to DB2, it is kind of a genuine doubt. Try helping me with this..

When we use a case statement (simple-case-statement-when-clause), in this -
the value of the expression prior to the first WHEN keyword is tested for equality with the value of each expression that follows the WHEN keyword. Right?
Then if the search condition is true, the THEN statement is executed. If the result is unknown or false, processing continues to the next search condition. If the result does not match any of the search conditions, and an ELSE clause is present, the statements in the ELSE clause are processed.

Now my doubt is, suppose the expression satisfies two conditions of the case statement, then will it execute the first one that satisfies? or will it execute all of them that do?
for eg.
A = 57;
B=0;
case when A <= 60 then B = 1
when A <= 80 then B = 2
else B = 3
end
In this case, B would first be set to 1. But then would it also reset to 2 after the case statement has been processed?

Thanks in advance! :)
Apr 25 '07 #1
1 4850
kalexin
20
Hi guys,
I have a doubt regarding the CASE statement. It might sound silly, but me being new to DB2, it is kind of a genuine doubt. Try helping me with this..

When we use a case statement (simple-case-statement-when-clause), in this -
the value of the expression prior to the first WHEN keyword is tested for equality with the value of each expression that follows the WHEN keyword. Right?
Then if the search condition is true, the THEN statement is executed. If the result is unknown or false, processing continues to the next search condition. If the result does not match any of the search conditions, and an ELSE clause is present, the statements in the ELSE clause are processed.

Now my doubt is, suppose the expression satisfies two conditions of the case statement, then will it execute the first one that satisfies? or will it execute all of them that do?
for eg.
A = 57;
B=0;
case when A <= 60 then B = 1
when A <= 80 then B = 2
else B = 3
end
In this case, B would first be set to 1. But then would it also reset to 2 after the case statement has been processed?

Thanks in advance! :)


Hi,
You may want to use a BREAK to exit the CASE statement. If you don't have a BREAK, the loop will continue all the way down.
Apr 26 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Tom | last post: by
1 post views Thread by mirth | last post: by
6 posts views Thread by ryan.mclean | last post: by
21 posts views Thread by Andy | last post: by
6 posts views Thread by deanfamily11 | last post: by
12 posts views Thread by rAinDeEr | last post: by
1 post views Thread by microsoft.public.dotnet.languages.vb | last post: by
7 posts views Thread by sam_cit | last post: by
13 posts views Thread by Satya | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.