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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

searching fields with spaces in them

Status
Not open for further replies.

cwizard

Programmer
Apr 6, 2001
3
GB
I have a data base of postcodes, stored with spaces in them (LL29 6AF), my users often miss the spaces out.
Can I use somthing like (this does not work!) Select address from postcodes where replace(postcode," ","") = [supplied postcode]
Or is there a simple way of removing the spaces from the postcodes in the table (21,000 records) so I could then remove the spaces in the user supplied postcode before running the select statement.
Nick
 
Your replace is correct, you just need to use single quotes:

Code:
SELECT * FROM t
WHERE REPLACE(postcode, ' ', '') = 'AB123CD'

You can use the same function to actually update the values already in the table:

Code:
UPDATE t
SET postcode = REPLACE(postcode, ' ', '')

--James
 
James, thank you! isn't it easy when you knoe how.

Nick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top