May 31, 2008 at 12:46 pm
Does anyone know if there's a maximum number of "When xxx THEN yyy" lines you can have within a single CASE statement?
Thanks.
Roger
May 31, 2008 at 1:09 pm
I can't say I know, but at the risk of sounding pedantic - if you have to ask the question, you should be considering a lookup table.....
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
May 31, 2008 at 1:23 pm
I don't know if there is a limit - at least, I cannot find anything that says there is. However, when I find that I have a very large statement I start to look at other ways to perform this operation.
For example, if I am converting some internal value/code to a human readable value - I will create a table instead and use the table.
I guess it really depends on what you are trying to do.
Jeff
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
May 31, 2008 at 2:20 pm
I know it does not provide any value (as already pointed out, a lookup table should be used), but I get an overflow with 9712 WHEN cases.
I just had to try this out 😉
SELECT CASE 'Hello'
WHEN '' THEN ''
.... 9710 more
WHEN '' THEN ''
END
But you can add more cases within these like
SELECT CASE 'Hello'
WHEN '' THEN
CASE 'Hello2'
WHEN '' THEN ''
.... x more
WHEN '' THEN ''
.... 9710 more
WHEN '' THEN ''
END
Now it's up to you to derive some value from this exercise 😉
Best Regards,
Chris Büttner
May 31, 2008 at 2:21 pm
Based on a test, 512 WHEN are accepted.
SQL = Scarcely Qualifies as a Language
May 31, 2008 at 3:46 pm
Matt Miller (5/31/2008)
I can't say I know, but at the risk of sounding pedantic - if you ask to ask the question, you should be considering a lookup table.....
Aye. Just because you can do something doesn't mean it's a great idea.
K. Brian Kelley
@kbriankelley
November 21, 2013 at 1:41 pm
Hey, I appreciate the test. I have a list of thousands of entries (people have a habit of typing the same thing very different ways) that I need to examine and then categorize. Initially I was looking at a monster CASE using LIKE to collapse the list. I guess it depends how much commonality there is to be found.:-D
November 21, 2013 at 2:07 pm
terrencepierce (11/21/2013)
Hey, I appreciate the test. I have a list of thousands of entries (people have a habit of typing the same thing very different ways) that I need to examine and then categorize. Initially I was looking at a monster CASE using LIKE to collapse the list. I guess it depends how much commonality there is to be found.:-D
yeah definitely sounds like using a lookup table would be better;
then you can join on the "WHEN" entry value to the lookup table, and get the translated "THEN" value from the table.
Lowell
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply