Try using the COALESCE function.I would also think you can do away with the subqueries. A couple of other tips: Don't start your stored procedure names with 'sp_' as it has an impact on performance if they're stored anywhere other than the master database. ([url]http://www.sqlmag.com/Article/ArticleID/23011/sql_server_23011.html[/url]). Also, it's better to specify exactly which fields you want returned rather than using select * ([url]http://www.asp101.com/tips/index.asp?id=125[/url])CREATE PROCEDURE [dbo].[My_Test]@name nvarchar(30),@address nvarchar(30)AsIF @name='ALL' SET @name=NULLIF @address='ALL' SET @address=NULLSELECT * FROM Emp_Address JOIN Emp_NameON Emp_Name.Employee_Id = Emp_Address.Employee_IdWHERE Emp_Address.Address = COALESCE(@address,Address) And Emp_Name.Employee_Name = COALESCE(@name,Employee_Name)
Each time you add a new parameter include the single 'IF' line and add a new condition to the select statement using coalesce.Hope that helpsAlan