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
Solved

Compound Field Expression in Query is BLANK

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
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.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

839 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