all groups > sql server programming > december 2004 >
You're in the

sql server programming

group:

select city from cities where city like (select '%' + city + '%' from stores where city like '%paul%')



select city from cities where city like (select '%' + city + '%' from stores where city like '%paul%') thomasamillergoogle NO[at]SPAM yahoo.com
12/4/2004 9:12:32 PM
sql server programming: select city from cities where city like (select '%' + city + '%' from
stores where city like '%st%')

You can see probably what I am trying to do. Is there a way to do this
RE: select city from cities where city like (select '%' + city + '%' Ed
12/4/2004 9:45:03 PM
you mean:
select city from cities where city in (Select city from stores where city
like '%st%')

Ed

[quoted text, click to view]
RE: select city from cities where city like (select '%' + city + '%' Ed
12/4/2004 9:59:01 PM
or you mean
select distinct a.* from customers a inner join orders b on a.customerid =
b.customerid where b.customerid like '%A%'

Ed

[quoted text, click to view]
RE: select city from cities where city like (select '%' + city + '%' Robert Davis
12/5/2004 7:05:03 AM
Select city
From Cities As C
Where Exists (Select 1 From Stores Where City Like '%st%' and C.City Like
'%' + city + '%')

Or

Select C.City
From Cities As C
Inner Join Stores As S On C.City Like '%' + S.City + '%'
Where S.City Like '%st%'


No, I don't understand what you are trying to do. I see this query as being
extremely flawed. For example, if there is a city in the Stores table named
Nestle and cities in the cities table named Nestle and Nestlevill, It will
return both cities, and I get the feeling that that's not what you want. And
I don't understand why you think a cursor would be needed.

Robert.

[quoted text, click to view]
RE: select city from cities where city like (select '%' + city + '%' thomas miller
12/5/2004 8:09:41 PM
I have a sql table named Stores that is standard, has columns
'city','state','storename'

The problem is that some stores have been data entered as
'st. paul'
'saint paul'
'east st. paul'
'west st. paul'
'west saint paul'.

my problem is that when the user queries for 'st. paul' it needs to
match ALL of the st. paul cities no matter how they were data entered.
So what I do is split function the "st. paul" and put it into a table
datatype... well see how I do it below.


ALTER function dbo.mt_getAllNamesForCity
(
@city varchar(100), @state varchar(1000)
)
returns @AllNamesForCity table (city varchar(200))


begin


--********* GET CENTER TARGET LATITUDE AND LONGITUDE
******************
declare @lat float(53)
declare @lon float(53)
declare @isGoodCriteria bit

select @lat = latitude, @lon = longitude from citycode where city =
@city and state = @state
if @lat is null
begin
select @lat = latitude, @lon = longitude from store where city =
@city and state = @state and country = 'us'
if @lat is null
begin
set @isGoodCriteria = 0
end
end

declare @Name varchar(100)

DECLARE splitUpName CURSOR FAST_FORWARD FOR --Declare
the cursor
select ( '%' + Value + '%') as spname from dbo.mt_split(@city, ' ')
--this splits the city name into separate words like %st.% and %paul% -
better than putting it into a temp table

OPEN splitUpName --Open the cursor
FETCH NEXT FROM splitUpName INTO @Name --Fetch next record
WHILE @@FETCH_STATUS = 0

BEGIN

insert into @AllNamesForCity (city)
select distinct city from store
where city like @Name and state = @state and
(
3958.75 * ( Atan(Sqrt(1 - power(((Sin(@Lat/57.2958) *
Sin(latitude/57.2958)) + (Cos(@Lat/57.2958) * Cos(latitude/57.2958) *
Cos((longitude/57.2958) - (@Lon/57.2958)))), 2)) /
((Sin(@Lat/57.2958) * Sin(latitude/57.2958)) + (Cos(@Lat/57.2958) *
Cos(latitude/57.2958) * Cos((longitude/57.2958) - (@Lon/57.2958)))))) +
0.0000000000000000001
< 20) -- make sure that the alternate city names it finds are within
20 miles


FETCH NEXT FROM splitUpName INTO @Name

END

CLOSE splitUpName --Close cursor
DEALLOCATE splitUpName --Deallocate cursor

return
end


*** Sent via Developersdex http://www.developersdex.com ***
AddThis Social Bookmark Button