Thursday, January 8, 2015

Where Condition Value or Null(If NULL return all rows)


Null

create table t1_null(sno int)
create table t2_null(sno int)
insert into t1_null values(1),(2),(3),(null),(null)
insert into t2_null values(1),(2),(3),(null),(null)

alter proc test(@ptsno int)
as
declare @vsno  int
begin
if(@ptsno='')
select @vsno=''
else
set @vsno=@ptsno
end
--select a.sno from t1_null a, t2_null b where case when a.sno is null then '' end ,a.sno
select sno from t1_null where (sno=@vsno or(@vsno is null or @vsno=''))
--(ID_Provider_Primary = @IDProvider OR (@IDProvider IS NULL OR @IDProvider = 0))
--http://p2p.wrox.com/sql-server-2000/35645-case-statement-where-clause-logic.html

No comments:

Post a Comment