March 8, 2010 at 7:29 pm
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?
March 8, 2010 at 7:51 pm
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.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
March 8, 2010 at 10:17 pm
...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
SQLkiwi blog
@SQL_Kiwi
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply