Solved

Select case statement in OPENQUERY statement

Posted on 2010-09-23
7
1,461 Views
Last Modified: 2012-05-10
The following is my code and works up till the second to last line or this one

Case when ELIG_NPS_BONUS IS NULL then BONUS_CNTL_NBR IS NULL else BONUS_CNTL_NBR end NPS_BONUS_CNTL_NBR

What I am trying to do is when  ELIG_NPS_BONUS IS NULL then another field BONUS_CNTL_NBR IS NULL  else show me what in the BONUS_CNTL_NBR

Is there a way to do this, it is an openquery that is hitting an Oracle server and returning the data.
Select * from OPENQUERY(SIDPERS, 'Select ACN, APP_Name, ADMIN_REMARKS, substr(SSN_SM,6,9), UIC, PARA, LINE, 
	GRADE, MOS, DT_EXPIRE, NCOID, 
	Case when ELIG_SLRP IS NULL then NULL else ''X'' end ELIG_SLRP,
	Case when SLRP_CNTL_NBR IS NULL then NULL else SLRP_CNTL_NBR end SLRP_CNTL_NBR,
	Case when ELIG_NPS_BONUS IS NULL then NULL  else ''X'' end ELIG_NPS_BONUS,
	Case when ELIG_NPS_BONUS IS NULL then BONUS_CNTL_NBR IS NULL else BONUS_CNTL_NBR end NPS_BONUS_CNTL_NBR
	from ACN.ACN_CNTL_NBR_TBL where ACN = ''09-119-003''')

Open in new window

0
Comment
Question by:kdeutsch
  • 3
  • 2
  • 2
7 Comments
 
LVL 33

Assisted Solution

by:knightEknight
knightEknight earned 125 total points
ID: 33748095
Case when ELIG_NPS_BONUS IS NULL and BONUS_CNTL_NBR IS NULL then null else BONUS_CNTL_NBR end NPS_BONUS_CNTL_NBR
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33748132
Select * from OPENQUERY(SIDPERS, 'Select ACN, APP_Name, ADMIN_REMARKS, substr(SSN_SM,6,9), UIC, PARA, LINE,
      GRADE, MOS, DT_EXPIRE, NCOID,
      Case when ELIG_SLRP IS NULL then NULL else ''X'' end ELIG_SLRP,
      Case when SLRP_CNTL_NBR IS NULL then NULL else SLRP_CNTL_NBR end SLRP_CNTL_NBR,
      Case when ELIG_NPS_BONUS IS NULL then NULL  else ''X'' end ELIG_NPS_BONUS,
      Case when ELIG_NPS_BONUS IS NULL then NULL else BONUS_CNTL_NBR end NPS_BONUS_CNTL_NBR
      from ACN.ACN_CNTL_NBR_TBL where ACN = ''09-119-003''')
0
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 225 total points
ID: 33748155
[Case when ELIG_NPS_BONUS IS NULL and BONUS_CNTL_NBR IS NULL then null else BONUS_CNTL_NBR end NPS_BONUS_CNTL_NBR]

is a long way to write just

BONUS_CNTL_NBR

because the CASE is only true when BONUS_CNTL_NBR is null, in which case.. it is already null... otherwise, show the value of BONUS_CNTL_NBR.
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 33

Expert Comment

by:knightEknight
ID: 33748177
You're right - I didn't even realize they were the same column.  (cut-n-paste)
0
 

Author Comment

by:kdeutsch
ID: 33748385
all

Ok, see the error of my ways, what about this, I just noticed I made another mistake in that I need to check for a zero or a null

Case when ELIG_SLRP = ''0'' or when ELIG_SLRP is NULL then NULL else ''X'' end ELIG_SLRP,
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33748448
Case when ELIG_SLRP = '0' or ELIG_SLRP is NULL then NULL else 'X' end ELIG_SLRP,

Since you are quoting the zero I assume it is varchar?
You could also do this

Case when nvl(ELIG_SLRP,'0') = '0' then NULL else 'X' end ELIG_SLRP,
0
 

Author Closing Comment

by:kdeutsch
ID: 33748461
thanks
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question