All records where there is a value

Hello

I am trying to retrieve all records where there is only a value in the T_Customers.Postcode with the following query, but it doesn't give me the right result, can anyone help?

SELECT     T_Customers.CustomerID, T_Customers.CustTypeID, T_Customers.Surname, T_Customers.Forename, T_Customers.TitleID, T_Customers.Ref1,
                      T_Customers.Add1, T_Customers.Add2, T_Customers.Add3, T_Customers.Add4, T_Customers.County, T_Customers.Postcode
                   
FROM         T_Customers
WHERE  exists ( select * from T_Customers where T_Customers.Postcode ='');
M_Boy76Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Patrick MatthewsCommented:
SELECT     T_Customers.CustomerID, T_Customers.CustTypeID, T_Customers.Surname, T_Customers.Forename, T_Customers.TitleID, T_Customers.Ref1,
                      T_Customers.Add1, T_Customers.Add2, T_Customers.Add3, T_Customers.Add4, T_Customers.County, T_Customers.Postcode
                   
FROM         T_Customers
WHERE T_Customers.Postcode IS NULL
0
tigin44Commented:
Try this


SELECT     T_Customers.CustomerID, T_Customers.CustTypeID, T_Customers.Surname, T_Customers.Forename, T_Customers.TitleID, T_Customers.Ref1,
                      T_Customers.Add1, T_Customers.Add2, T_Customers.Add3, T_Customers.Add4, T_Customers.County, T_Customers.Postcode
                   
FROM         T_Customers
WHERE  T_Customers.Postcode IS NOT NULL;
0
M_Boy76Author Commented:
Both queries returned records where the post codes are empty?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Patrick MatthewsCommented:
M_Boy76,

1) Please try restating what you are looking for

2) Is the Postcode column going to be NULL, or a zero-length string?  They are NOT the same thing :)

Regards,

Patrick
0
M_Boy76Author Commented:
I have some records that have postcodes, in the format xx11 2km, and some of these records dont have post codes,.

Now what i want to do is retrieve all records where the record has a post code.
0
Patrick MatthewsCommented:
M_Boy76 said:
>>Now what i want to do is retrieve all records where the record has a post code.

Did you try tigin44's suggestion?  That ought to do it...
0
BrandonGalderisiCommented:
What about this:



SELECT     T_Customers.CustomerID, T_Customers.CustTypeID, T_Customers.Surname, T_Customers.Forename, T_Customers.TitleID, T_Customers.Ref1, 
                      T_Customers.Add1, T_Customers.Add2, T_Customers.Add3, T_Customers.Add4, T_Customers.County, T_Customers.Postcode
                   
FROM         T_Customers 
WHERE len(isnull(T_Customers.Postcode,'')>0

Open in new window

0
ZberteocCommented:
How about this:
SELECT     
	T_Customers.CustomerID, 
	T_Customers.CustTypeID, 
	T_Customers.Surname, 
	T_Customers.Forename, 
	T_Customers.TitleID, 
	T_Customers.Ref1, 
	T_Customers.Add1, 
	T_Customers.Add2, 
	T_Customers.Add3, 
	T_Customers.Add4, 
	T_Customers.County, 
	T_Customers.Postcode
FROM
	T_Customers 
WHERE 
	isnull(ltrim(rtrim(T_Customers.Postcode)),'')<>''

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.