Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to construct a sort of "Property Search" Query for my site.

Where I am so far:
I have a multi select dropdownlist on my site that contains "Neighborhoods" within a city. I am passing the selected IDs of that dropdown to a stored proc via a comma delimited list (varchar). I am then splitting those values using a User Defined Function which give me back a simgle column called ID that contains a row for each selected value.
EXP:

ID
---
2
3
4
6
8

My Query:
I have a table that has many "Properties" These properties each reside within one of the "Areas", so each has an Area_ID. Of course many properties can belong to a category.
I need to bring back all of the properties that belong to all of the "Areas" that were selected.

Basically I am confused on how I should approach this query. Joins, Temp table, Where IN, etc.

Any help is appreciated

Jay
Posted
Comments
Maciej Los 11-Feb-13 17:13pm    
You can achieve that using: JOIN's and WHERE FieldName IN(arg1, ar2, argN) clause.

1 solution

If your UDF gives you back a table..

SQL
Select xxx from Properties AS P join theUDFTable AS U on  P.Area_Id = U.AreaID
 
Share this answer
 
Comments
jhoward73 12-Feb-13 10:01am    
Exactly what I needed and works perfectly.
Not sure why I made it so difficult.

Thanks so much _Maxxx

Here is the code I ended up with:
@delimitedlist varchar(100)
as
begin
create table #AreasTemp (ID int, value int)
insert into #AreasTemp select * from f_Split_byDelimiter(@delimitedlist,',')
Select StreetAddress,area
from dbo.Properties AS P join #AreasTemp AS AT on P.area = AT.value
order by Area
end

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900