Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to create a search criteria with option to narrow your search

Posted on 2012-03-16
3
Medium Priority
?
241 Views
Last Modified: 2012-03-19
Hi there,

I have got a postcodes table which contains the postcodes and the street(s) associated with it. I have got a child table which contains the full address of a business, a commercial building or residential building etc.
My reuirement is that on asp.net the users can enter the post code and all the addresses associated with that post code should be displayed. Which is very easy to achieve. But the problem comes when users try to search a specific business with in that postcode.
For example the criteria can be
Search me a macdonalds in SK4  1BS or search me macdonalds and pizza hut in SK4 1BS and the list of the businesses can expand in search criteria.

Can you please help how do i achieve this? as i am confused that in my stored procedure i can not give here an and condition in where clause because the user can leave the business field blank.

The fron end asp.net has also got a plus button to add more text boxes to be included in search criteria. But all the text boxes will only allow to enter the business.

Best regards,
0
Comment
Question by:shah36
3 Comments
 
LVL 25

Expert Comment

by:jogos
ID: 37729658
where business like '%'+isnull(@searchstring,'')+'%'
0
 
LVL 8

Accepted Solution

by:
Crashman earned 2000 total points
ID: 37729677
example
create sp_search 
@field int = null,
@field2 varchar(10) = null
@field3 varchar(10) = null
as
begin
select t.* from tblExample t where
( @field is null or t.FieldA = @field) 
and  (@field2 is null or t.fieldB = @field2)
and (@field3 is null or t.fieldC = @field3)

end

Open in new window


and pass a null in the parameter combination

execute sp_search 1,null,'B'

Open in new window

0
 
LVL 9

Expert Comment

by:sarabhai
ID: 37730885
if you need search field to be blank for particular column then in where clause specify the condition like below

WHERE column_Name = CASE WHEN @para_column_name NOT NULL THEN para_column_name ELSE  column_Name END
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question