Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2012-03-16
3
Medium Priority
?
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

715 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