Solved

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

Posted on 2012-03-16
3
233 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 500 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now