Solved

Blank space where value is NULL

Posted on 2014-10-28
10
123 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 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
Webinar: Security & Encryption in the MySQL world

Join Percona’s Solutions Engineer, Dimitri Vanoverbeke as he presents “Security and Encryption in the MySQL world” on Thursday, July 6, 2017 at 7:00 am PDT / 10:00 am EDT (UTC-7).

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

728 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