Solved

Compound Field Expression in Query is BLANK

Posted on 2003-12-03
5
260 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how the fundamental information of how to create a table.

747 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

10 Experts available now in Live!

Get 1:1 Help Now