By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,377 Members | 1,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,377 IT Pros & Developers. It's quick & easy.

Stored Procedure for Searching

P: 22
Dear All,
I have one table

eg: Employee (Table Name)
Fields (Columns)

Eno,Ename,Dept,Designation,Date of Birth,PhNumber, City
Some are not nulls and some are nulls

I need to write a Stored Procedure to search by all the fields.
or What ever the user entered in all the fields like that it has to search

How to write the Stored procedure to do best performance in searching

Thanks in Advance
May 27 '08 #1
Share this Question
Share on Google+
1 Reply


deepuv04
Expert 100+
P: 227
Dear All,
I have one table

eg: Employee (Table Name)
Fields (Columns)

Eno,Ename,Dept,Designation,Date of Birth,PhNumber, City
Some are not nulls and some are nulls

I need to write a Stored Procedure to search by all the fields.
or What ever the user entered in all the fields like that it has to search

How to write the Stored procedure to do best performance in searching

Thanks in Advance
Hi,
Here is the sample code, add the columns or parameters as per your requirement.

[code = sql]
CREATE PROCEDURE EmployeeSearch(
@ENO int = NULL,
@Ename varchar(100) = NULL,
@Designation varchar(100) = NULL
) AS
BEGIN

SELECT Eno,Ename,Dept,Designation,Date of Birth,PhNumber, City
FROM Employee
WHERE Eno = ISNULL(@ENO,Eno) AND
Ename = ISNULL(@Ename,Ename) AND
Designation = ISNULL(@Designation,Designation)
END


[/code]
Thanks
May 27 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.