SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Multiple parameters


Multiple parameters

Author
Message
CrazyMe
CrazyMe
Valued Member
Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)Valued Member (67 reputation)

Group: General Forum Members
Points: 67 Visits: 84
Student Table Structure

Firstname Lastname FullName Age
ABC XYZ ABCXYZ 12
DEF GHI DEFGHI 14
JKL MNO JKLMNO 16

I create an SP as below
Create procedure
SearchStudent
(@i_firstname varchar(50),
@i_lastname varchar(50),
@i_fullname varchar(50),
@i_age int)

The search can be done by either using Firstname or Lastname or Fullname or Age.

For e.g if I'm searching by providing the Firstname alone then the other parameters are blank/null...

select firstname,lastname,fullname,age
from student
where firstname like '@i_firstname%'
and lastname like '@i_lastname%'
and fullname like '@i_fullname%'
and age = @i_age

How the search can be achieved by providing any one of the parameter?


Kindest Regards,

Arunkumar


Reputation is what other people know about you. Honor is what you know about yourself."--


RBarryYoung
RBarryYoung
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14732 Visits: 9518
Please read this Article: Example of Safely Using Dynamic SQL with User Selected Table Name. Just do what it says, except for your column name instead of the table name.

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Paul White
Paul White
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15684 Visits: 11355
...and if you would like some more options, take a look at Erland's article on the subject: http://www.sommarskog.se/dyn-search-2005.html



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search