Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Compound Field Expression in Query is BLANK

Posted on 2003-12-03
5
Medium Priority
?
300 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
[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
  • 3
5 Comments
 
LVL 9

Accepted Solution

by:
PaulBarbin earned 2000 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:Dishan Fernando
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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

705 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