Solved

Select case statement in OPENQUERY statement

Posted on 2010-09-23
7
1,453 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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 video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

803 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