SQL Server . SQL Server , null, , , not null.
option (recompile) SQL Server 2005, SQL Server 2008 , .
, , SQL Server null.
T-SQL
, , . SP , .
create table T
(
ID int identity primary key,
Col1 int,
Col2 int
);
go
create index IX_T on T(Col1);
go
create procedure GetT
@Col1 int,
@Col2 int
as
select ID
from T
where (Col1 = @Col1 or @Col1 is null) and
(Col2 = @Col2 or @Col2 is null)
option (recompile);
go
exec GetT 1, null
exec GetT 1, 1