Solved

Compound Field Expression in Query is BLANK

Posted on 2003-12-03
5
277 Views
Last Modified: 2012-08-14
I use the following query to run a report in my database:

*****************************************************
SELECT TBL_CASE.CID,
    TBL_PLAINTIFF.PLNAME + ', ' + TBL_PLAINTIFF.PFNAME + ' ' + TBL_PLAINTIFF.PMI
     + ' ' + TBL_PLAINTIFF.Sufix AS pltFull, TBL_PLAINTIFF.SSN,
    TBL_PLAINTIFF.DOB, TBL_PLAINTIFF.DOD,
    TBL_PLAINTIFF.PADDRESS, TBL_PLAINTIFF.AKA,
    TBL_PLAINTIFF.diagnosis, TBL_CASE.[CAUSE NUMBER],
    TBL_CASE.[STYLE PLAINTIFF],
    TBL_CASE.[STYLE DEFENDANT], TBL_CASE.COURT,
    TBL_COUNTY.COUNTY, TBL_PLAINTIFF.[Pltf ID],
    TBL_PLAINTIFF.Occupation, TBL_CASE.comments,
    TBL_PLAINTIFF.[work site], TBL_PLAINTIFF.Settled,
    TBL_PLAINTIFF.[DE comments]
FROM dbo.TBL_CASE INNER JOIN
    dbo.[TBL_PETITION OF ENTRY] ON
    dbo.TBL_CASE.CID = dbo.[TBL_PETITION OF ENTRY].CID INNER
     JOIN
    dbo.TBL_PLAINTIFF ON
    dbo.[TBL_PETITION OF ENTRY].PID = dbo.TBL_PLAINTIFF.PID INNER
     JOIN
    dbo.TBL_COUNTY ON
    dbo.TBL_CASE.CNTYID = dbo.TBL_COUNTY.CNTYID
*****************************************************

The query column in question is the expression which creates the [pltFull] column.  It combines the first, middle, last name and suffix fields to display an individual's full name as "Doe, John A. Jr." etc....  What I have found, however, is if ALL FOUR component fields to this expression are not populated, then NO value is returned.

My question is what is the quickest and most efficient method to have the query return full names, even if the middle initial field or suffix field is not populated?
0
Comment
Question by:FunkiNATEr
  • 3
5 Comments
 
LVL 9

Accepted Solution

by:
PaulBarbin earned 500 total points
ID: 9872608
Typically first and last are required, so you might not need it on all columns.
Use the ISNULL method:

TBL_PLAINTIFF.PLNAME + ', ' + TBL_PLAINTIFF.PFNAME + ' ' + ISNULL(TBL_PLAINTIFF.PMI, '')
     + ' ' + ISNULL(TBL_PLAINTIFF.Sufix, '') AS pltFull, TBL_PLAINTIFF.SSN,

Paul
0
 
LVL 8

Expert Comment

by:dishanf
ID: 9872615
not populated mean NULL VALUES OR BLANK '' Column??
0
 
LVL 9

Expert Comment

by:PaulBarbin
ID: 9872622
If you don't already know then the reason this happens is that one of those columns is NULL.  NULL means UNKNOWN, and UNKNOWN plus anything is still UNKNOWN.

Another way to solve this problem is by changing a db option CONCAT_NULL_YIELDS_NULL
by running
SET CONCAT_NULL_YIELDS_NULL OFF

Paul

0
 
LVL 9

Expert Comment

by:PaulBarbin
ID: 9875406
I appreciate the points and the grade.
0
 

Author Comment

by:FunkiNATEr
ID: 9875414
No problem -- I am sure I will have more in the near future.  :-)
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

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.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

813 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

19 Experts available now in Live!

Get 1:1 Help Now