Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query returns only fields that have a value

Status
Not open for further replies.

mbusa11

MIS
Oct 2, 2005
12
US
How do I output fields that only have a valid value in the database and skip the output of fields that have No value in the database.

example

First Name : Jen
Middle Initial : A
Last Name : Brooke


if for example the person doesnt have a middle initial

I want the output to be like

First Name : Kelly
Last Name : Sue

Instead of

First Name : Kelly
Middle Initial :
Last Name : Sue
 
You could use dynamic SQL to do this, but I recommend against it.

Instead, you should modify your front end app so that it ignores fields that are blank (i.e. don't show it to the user).



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
This will only work if you return 1 row only
what if row 1 has a middle name and row 2 doesn't, what do you do in that case

“I sense many useless updates in you... Useless updates lead to fragmentation... Fragmentation leads to downtime...Downtime leads to suffering..Fragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" --
 
Maybe:
Code:
WHERE FirstName IS NOT NULL
        OR MiddleName IS NOT NULL
        OR LastName IS NOT NULL

-SQLBill

Posting advice: FAQ481-4875
 
thanx for the response guys .. but i have no choice, but to put it in the query , so it cannot be on the front end..

as far as bills post.. id like to hear more.. what exactly do u mean by puttint that stuff in there where clause.. sorry im a newbie to this..

can u like give me a simple query as an example..
 
If first/middle/last name are columns then... tables are simply said squared. You cannot drop/hide a column here and there. Either entire column is present or not.

What is exact table structure you have?

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top