Solved

Blank space where value is NULL

Posted on 2014-10-28
10
119 Views
Last Modified: 2014-10-28
I have a report with the following code entered for reporting insurance information.

CASE WHEN AI.InsuranceSeqID = '1' then AI.InsuredPolicyNumber END AS 'PolicyNumber1',
                  CASE WHEN AI.InsuranceSeqID = '2' then AI.InsuredPolicyNumber END AS 'PolicyNumber2',
                        CASE WHEN AI.InsuranceSeqID = '3' then AI.InsuredPolicyNumber END AS 'PolicyNumber3',
                              CASE WHEN AI.InsuranceSeqID = '4' then AI.InsuredPolicyNumber END AS 'PolicyNumber4',

When I run the report, if the patient does not have an AI.InsuranceSeqID of 2,3,or 4, it is returning NULL in the column.  I would like this to be blank if there is no policy number for this SeqID,

It currently prints.  PolicyNumber1   PolicyNumber2 PolicyNumber3  PolicyNumber4
                                  t1234567890        NULL                   NULL                    NULL

I want:                     PolicyNumber1   PolicyNumber2 PolicyNumber3  PolicyNumber4
                                 1234567890
0
Comment
Question by:kvrogers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +3
10 Comments
 
LVL 25

Accepted Solution

by:
Lee Savidge earned 500 total points
ID: 40408647
Replace with a blank using isnull()

isnull(CASE WHEN AI.InsuranceSeqID = '1' then AI.InsuredPolicyNumber END, '') AS 'PolicyNumber1',
isnull(CASE WHEN AI.InsuranceSeqID = '2' then AI.InsuredPolicyNumber END, '') AS 'PolicyNumber2',
isnull(CASE WHEN AI.InsuranceSeqID = '3' then AI.InsuredPolicyNumber END, '') AS 'PolicyNumber3',
isnull(CASE WHEN AI.InsuranceSeqID = '4' then AI.InsuredPolicyNumber END, '') AS 'PolicyNumber4',

Open in new window

0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 40408653
To convert NULL to an empty space '' in T-SQL, use either ISNULL(column_name, '') or COALESCE(column_name, '').

Since you're doing this for reporting, it might be more appropriate to pull this off in the reporting layer, and not the data set.  Your call.
0
 
LVL 22

Expert Comment

by:Steve Wales
ID: 40408655
Untested, but you should be able to do:

isnull(CASE WHEN AI.InsuranceSeqID = '1' then AI.InsuredPolicyNumber END, ' ') AS 'PolicyNumber1',
isnull(CASE WHEN AI.InsuranceSeqID = '2' then AI.InsuredPolicyNumber END, ' ') AS 'PolicyNumber2', 
isnull(CASE WHEN AI.InsuranceSeqID = '3' then AI.InsuredPolicyNumber END, ' ') AS 'PolicyNumber3', 
isnull(CASE WHEN AI.InsuranceSeqID = '4' then AI.InsuredPolicyNumber END, ' ') AS 'PolicyNumber4', 

Open in new window

ISNULL is a valid function for both MySQL and SQL Server (since you tagged both in your question).
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40408793
Insert before each END

ELSE ''
0
 
LVL 32

Expert Comment

by:awking00
ID: 40408869
CASE WHEN AI.InsuranceSeqID = '1' then coalesce(AI.InsuredPolicyNumber,'') END AS 'PolicyNumber1',
CASE WHEN AI.InsuranceSeqID = '2' then coalesce(AI.InsuredPolicyNumber,'') END AS 'PolicyNumber2',
CASE WHEN AI.InsuranceSeqID = '3' then coalesce(AI.InsuredPolicyNumber,'') END AS 'PolicyNumber3',
CASE WHEN AI.InsuranceSeqID = '4' then coalesce(AI.InsuredPolicyNumber,'') END AS 'PolicyNumber4',

Open in new window

0
 

Author Comment

by:kvrogers
ID: 40409175
Thank you for your prompt reply.  This worked perfectly.
0
 
LVL 32

Expert Comment

by:awking00
ID: 40409231
>>This worked perfectly<<
And Lee Savidge's didn't?
0
 
LVL 22

Expert Comment

by:Steve Wales
ID: 40409263
Points should really have gone to Lee - his was the exact same response as mine.  Filing Request for attention for Moderators to review.
0
 

Author Comment

by:kvrogers
ID: 40409317
I started from the last entry which was in my email.  That one worked.  I am sorry I missed Lee's.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
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.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

756 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