Solved

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

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
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
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

623 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