Solved

Blank space where value is NULL

Posted on 2014-10-28
10
113 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
  • 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
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40408793
Insert before each END

ELSE ''
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Suggested Solutions

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

914 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now