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)
 sql trimming spaces

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2005-03-14 : 05:08:59
in my table i have a list of states and if the state includes a space there will be a space.

so los angeles is in the table as los angeles

now In my query I want to pull up the los angeles row regardless of wether I do

select * from zipcodes where city like 'los angeles'

or

select * from zipcodes where city like 'losangeles'
(without the spaces)

What's the best way to go about this?

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-03-14 : 05:33:11
declare @city varchar(100)
set @city = 'los angeles' -- or 'losangeles'
select * from zipcodes where replace(city, ' ', '') like replace(@city, ' ', '')

Go with the flow & have fun! Else fight the flow
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2005-03-14 : 05:50:41
Thanks for your help :)
Exactly what I needed! I appreciate it
Go to Top of Page
   

- Advertisement -