473,472 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Case statement in where clause is hanging!

1 New Member
Hi Everybody

I am writing this statement,but is it hanging! Can anybody correct me? Any help will be appreciated!

select (cba.billing_name1||' '||cba.billing_name2) as cust_bill_name from USRP.cust_billing_acct cba,USRP.circuit ckt,USRP.customer cust
where cba.MCN = case when ckt.CKT_MCN is NOT NULL THEN ckt.CKT_MCN ELSE ( select cust.MCN from USRP.customer cust where ckt.C_ID = cust.CUSTOMER_ID) end
AND cba.GRC = case when ckt.CKT_GRC IS NOT NULL THEN ckt.CKT_GRC ELSE (select cust.GRC from USRP.customer cust where ckt.C_ID = cust.CUSTOMER_ID) end
AND cba.SOC =case when ckt.CKT_SOC IS NOT NULL THEN ckt.CKT_SOC ELSE ( select cust.SOC from USRP.customer cust where ckt.C_ID = cust.CUSTOMER_ID) end
Aug 11 '07 #1
2 4712
amitpatel66
2,367 Recognized Expert Top Contributor
Why you need to use a sub queries in your case when you can make things simpler:

Expand|Select|Wrap|Line Numbers
  1.  
  2. select (cba.billing_name1||' '||cba.billing_name2) as cust_bill_name from USRP.cust_billing_acct cba,USRP.circuit ckt,USRP.customer cust 
  3. where cba.MCN = case when ckt.CKT_MCN is NOT NULL THEN ckt.CKT_MCN ELSE cust.MCN end
  4. AND cba.GRC = case when ckt.CKT_GRC IS NOT NULL THEN ckt.CKT_GRC ELSE cust.GRC end
  5. AND cba.SOC =case when ckt.CKT_SOC IS NOT NULL THEN ckt.CKT_SOC ELSE cust.SOC end 
  6.  
  7.  
Try this and post back in case of any issues
Nov 6 '08 #2
Pilgrim333
127 New Member
Hi,

In the FROM clause the addition of the table USRP.customer cust is not needed, and gives you a cartesian product. If the table USRP.customer is populated with a lot of rows, then it can cause your query to hang.

Why don't you use the nvl function instead of the case statement?

Pilgrim.
Nov 6 '08 #3

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

Similar topics

2
by: Largo SQL Tools | last post by:
Can anyone tell me if it's possible to use a Case statement in a Where clause, and if so, the proper syntax? J.R. Largo SQL Tools The Finest Collection of SQL Tools Available...
1
by: mirth | last post by:
I would like to update a decimal column in a temporary table based on a set of Glcodes from another table. I search for a set of codes and then want to sum the value for each row matching the...
3
by: A.V.C. | last post by:
Hello, I found members of this group very helpful for my last queries. Have one problem with CASE. I can use the column name alias in Order By Clause but unable to use it in WHERE CLAUSE. PLS...
4
by: Chad Richardson | last post by:
I've always been mistified why you can't use a column alias in the group by clause (i.e. you have to re-iterate the entire expression in the group by clause after having already done it once in the...
9
by: Michael | last post by:
Hi all, I would like to get people's opinion about executing SQL statements in C# (or any other .NET language really). I used to create my SQL statement by building a string and replacing single...
8
by: Jeff Gilbert | last post by:
Hello all. I'd appreciate some help with this one: First the DDL: CREATE TABLE ( NOT NULL , NULL , NOT NULL , (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , NOT NULL...
7
by: mandible | last post by:
Hello I'm trying to have some control on how my data is ordered depending on an input parameter my question is in a stored procedure how can I do something like this at the end of my...
1
by: priyanka2203 | last post by:
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...
5
by: Sascha.Moellering | last post by:
Hi, I receive the error code SQL0338N if I try to compile this statement (part of the statement): .... left outer join lateral (SELECT * FROM LIZSYSABA.VWZL0359TBS WHERE tbs_name = CASE WHEN...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.