[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Select case statement in OPENQUERY statement

Posted on 2010-09-23
7
Medium Priority
?
1,658 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 500 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 900 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example, show how to take different types of Oracle backups using RMAN.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

830 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