Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 11-Feb-13 10:23am
Comments
Maciej Los at 11-Feb-13 17:13pm
   
You can achieve that using: JOIN's and WHERE FieldName IN(arg1, ar2, argN) clause.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

If your UDF gives you back a table..
 
Select xxx from Properties AS P join theUDFTable AS U on  P.Area_Id = U.AreaID
  Permalink  
Comments
jhoward73 at 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)

  Print Answers RSS
0 Dnyaneshwar@Pune 604
1 thatraja 370
2 OriginalGriff 319
3 Sergey Alexandrovich Kryukov 243
4 Gihan Liyanage 194
0 OriginalGriff 737
1 Dnyaneshwar@Pune 604
2 Kornfeld Eliyahu Peter 505
3 Sergey Alexandrovich Kryukov 372
4 thatraja 370


Advertise | Privacy | Mobile
Web02 | 2.8.140902.1 | Last Updated 11 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100