I created a searcher as follows :
create procedure [dbo].[search_pazhoheshgar]
@se_code_melli varchar(10) = NULL,
@se_name nvarchar(30) = NULL,
@se_family nvarchar(30) = NULL,
@se_name_uni nvarchar(100) = NULL,
@se_name_reshte_tahsili nvarchar(50) = NULL
as
begin try
begin tran
set nocount on;
select
sabt.code_melli, sabt.name, sabt.family,
sabt_como_univercity.name_uni,
sabt_como_reshte.name_reshte_tahsili
from
sabt
inner join
sabt_como_univercity on sabt.univercity = sabt_como_univercity.id_uni
inner join
sabt_como_reshte on sabt.name_reshte = sabt_como_reshte.id_reshte_tahsili
where
@se_code_melli is not null
and @se_code_melli <> ''
and sabt.code_melli like '%' + @se_code_melli + '%'
or @se_name is not null
and @se_name <> ''
and sabt.name like '%' + @se_name + '%'
or @se_family is not null
and @se_family <> ''
and sabt.family like '%' + @se_family + '%'
or @se_name_uni is not null
and @se_name_uni <> ''
and sabt_como_univercity.name_uni like '%' + @se_name_uni + '%'
or @se_name_reshte_tahsili is not null
and @se_name_reshte_tahsili <> ''
and sabt_como_reshte.name_reshte_tahsili like '%' + @se_name_reshte_tahsili + '%'
commit tran
end try
begin catch
rollback tran
return -1
end catch
When I search with a parameter, it is not a problem. But when I set several parameters, the last entered parameter is placed as the search criterion. Obviously, this problem is due to the presence of OR. Now if I use AND instead of OR, I can not put a value NULL, because the search is ineffective. What should I do?