Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Need help creating search sproc

Author  Topic 

tiwas
Starting Member

37 Posts

Posted - 2011-12-18 : 12:49:27
Hi guys,
I need to create a search sproc. Let's say it's a people database and the user can search for anything they'd like out of first name, last name, address 1, address 2, city
Then I'd have something like
nvarchar(max) firstname = null,
bit firname_exact = 0,
nvarchar(max) lastname = null,
bit lastname_exact = 0,
nvarchar(max) address1 = null,
nvarchar(max) address2 = null,
nvarchar(max) city = null

Now, the select would proably be something like
select * from people
where
...and this is the hard part. I guess I need to use a case statement in the where clause, but as not all of these are patials and the user can select to check only exact matches or partial matches for some of the fields, I was wondering if I can use 'like' for both exact and partial matches. Will this add overhead to the sproc? Are there any built-in functions for doing this?

Cheers!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-18 : 12:55:10
you can use like for both exact and partial matches but performance using LIKE would be obviously below =

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-12-18 : 13:46:01
Also, you should be aware of this: http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/

--
Gail Shaw
SQL Server MVP
Go to Top of Page
   

- Advertisement -