tags:

views:

69

answers:

3

Hello,

I have a database on a SQL Server 2000 server. This database has a table called "Person" that has a field call "FullName" that is a VARCHAR(100).

I am trying to write a query that will allow me to get all records that have a name. Records that do not have a name have a FullName value of either null or an empty string. How do I get all of the Person records have a FullName? In other words, I want to ignore the records that do not have a FullName. Currently I am trying the following:

SELECT
  *
FROM
  Person p
WHERE
 p.FullName IS NOT NULL AND
 LEN(p.FullName) > 0

Thank you

+1  A: 

This would be the preferred way I suppose

SELECT
    *
FROM
    Person p
WHERE
    p.FullName <> ''
WoLpH
IS NOT NULL part is not needed - second part of where excludes such records anyway.
Arvo
Right... you are correct :)
WoLpH
A: 

How about (ISNULL)

SELECT 
  * 
FROM 
  Person p 
WHERE 
 ISNULL(p.FullName,'') <> ''
astander
you don't need the ISNULL() because `null<>''` is false
KM
That could be debatable X-) http://msdn.microsoft.com/en-us/library/aa259229(SQL.80).aspx
astander
+1  A: 

make your data consistent first:

UPDATE Person
    SET FullName=NULL
    WHERE FullName != ''

then query your data without worrying about inconsistencies:

SELECT 
    *
    FROM Person
    WHERE FullName IS NOT NULL

IF you don't/can't to fix your data, you can use this:

SELECT 
    *
    FROM Person
    WHERE FullName != ''
KM