Click here to Skip to main content
12,398,000 members (50,633 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: .NET T-SQL DropDownList
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 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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 11 Feb 2013
Copyright © CodeProject, 1999-2016
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