Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Ignoring Whitespace in WHERE Clause

Author  Topic 

fizzer
Starting Member

10 Posts

Posted - 2006-10-18 : 09:58:20
Hi,

I have the following query:

SELECT TimeZone FROM PostalCodesTable
WHERE PostalCode='H1A2W6'

Some of the postcodes are stored in the database with spaces and some without. The user can only enter postcodes without spaces. So how Would I get a match if for in the above example case, the postcode was stored as 'H1A 2W6'?

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2006-10-18 : 10:05:36
Look up "Replace" in BOL (Books Online) or do a search for "Whitespace" here on these forums.

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

fizzer
Starting Member

10 Posts

Posted - 2006-10-18 : 11:07:11
Iv'e looked at the REPLACE function but not sure that that's what I need. ie. In my first post, I would have to add a space not replace anything.

The reason for this (I think) is that I cannot use the REPLACE in the Where Clause.

EDITED:- ignore my post this seems to work:
SELECT TimeZone
FROM PostalCodesTable WHERE REPLACE(PostalCode,' ','') ='H1A2W6'

Many thanks
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2006-10-18 : 14:45:47
It is always BEST when you solve your own problem. I will bet you learned a LOT more by finding the answer than having it given to you.

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page
   

- Advertisement -