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 2005 Forums
 Transact-SQL (2005)
 How to: 1 sproc, 2 different input parms?

Author  Topic 

Paul323
Starting Member

1 Post

Posted - 2007-05-05 : 15:52:30
I have created an sproc (callable from an ASP.NET) that retrieves user information data from a table based on an input parameter for the user id. Is there a method to author that sproc so it is dynamic enough that it could also return that user info if I passed in the user's last name? I have lots of flexibility to create different input params; I am hoping to avoid writing 2 sprocs to do basically the same thing with only the WHERE clause being different.

Basically, I want the same sproc to get me info by id if I give it an id, or by name if I give it a name.

My thanks.

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-05-05 : 16:19:27
read this for different methods on dynamic search conditions:

http://www.sommarskog.se/dyn-search.html

in your case since you have only two fields to search on, I'd probably go the IF route: http://www.sommarskog.se/dyn-search.html#IF



www.elsasoft.org
Go to Top of Page
   

- Advertisement -