Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 CASE PROBLEM

Author  Topic 

verovaldez
Starting Member

1 Post

Posted - 2007-08-02 : 11:56:58
Hi!

I have a problem with this query:

Select isnull( case when t5.C>0 then t5.C else case when t4.C>0
then t4.C else case when t3.C>0
then t3.C else case when t2.C>0
then t2.C else case when t6.C>0
then t6.C else case when t7.C>0
then t7.C else case when t8.C>0
then t8.C else case when t9.C>0
then t9.C else case when t10.C>0
then t10.C else case when t11.C>0
then t11.C else case when t12.C>0
then t12.C else t13.C end end end end end end end end end end end ,0)
FROM TABLE1 t1 , TABLE2 t2 , TABLE3 t3 , TABLE4 t4 , TABLE5 t5 , TABLE6 t6 , TABLE7 t7 , TABLE8 t8 , TABLE9 t9 , TABLE10 t10 , TABLE11 t11 , TABLE12 t12 , TABLE13 t13
WHERE .....

This cause the next error:

Server: Msg 125, Level 15, State 4, Line 11
Case expressions may only be nested to level 10.


How can I resolve this?

I would appreciate some help ASAP

thanks

sshelper
Posting Yak Master

216 Posts

Posted - 2007-08-02 : 12:00:48
No need for a nested case. Re-write your code to something like this:

Select isnull(
case when t5.C>0 then t5.C
when t4.C>0 then t4.C
when t3.C>0 then t3.C .. and so on


SQL Server Helper
http://www.sql-server-helper.com
Go to Top of Page
   

- Advertisement -