Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The best way to use a stored procedure for a search? 1

Status
Not open for further replies.

modika11

Programmer
Jan 31, 2008
20
Hi All,

although i have done this using several ways i am sitting here thinking what way is actually the best? I have a job search which will search against mutiple criteria. I have written stored procedures whith loads of conditional statments depending on what search criteria has been provided depends on how the SQL is written, this is not dynamic SQL it is normal SQL with a very detailed (complicated) where clause. I have also done it using dynamic SQL within a stored procedure, obviously with some conditional statements to see what needs to go in the where clause.

How do you guys deal with searches, in particular ones with mutiple criteria?

Thanks,

Rob
 
IF statements.

Or I break it apart into multiple procs if it starts to get too cumbersome.

You can also create a variable for each optional field with a default value that will catch all (ie. '%'). Pass only the arguments you want to search against.

"If I were to wake up with my head sewn to the carpet, I wouldn't be more surprised than I am right now.
 
Thanks for all your responses guys and thank you for the link Tyson was an interesting read.
 
Thanks for those links, Tyson and Mark. Both were helpful and gave me some direction into another problem I was trying to resolve (in the best way).

------------------------------------------------------------------------------------------------------------------------
"As for the bureacratic, politically-correct, mollycoddling, asinine, Romper Room antics of...clients and management, just read up on Dilbert. It's not funny - it's a training manual."
- Mike
 
I encourage you all NOT to use dynamic SQL.

For more on the topic of using stored procedures for searches (and dynamic sql, too), see this thread. Then, search the web for "dynamic sql is bad" and read a few of the many many hits you'll get.

 
Don't worry... I am rather aware of the negative aspects of using dynamic SQL and was referring to other options. But thanks for the reminder. ;-)

------------------------------------------------------------------------------------------------------------------------
"As for the bureacratic, politically-correct, mollycoddling, asinine, Romper Room antics of...clients and management, just read up on Dilbert. It's not funny - it's a training manual."
- Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top