?
Solved

Blank space where value is NULL

Posted on 2014-10-28
10
Medium Priority
?
126 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 2000 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 66

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
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.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

770 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