NullIf(expression1,expression2)
If both expressions values are same then return Null otherwise return first expression values.
create table Store
(
Id int identity(1,1),
Store varchar(50),
Actual int,
Goal int
)
insert into Store(Store,Actual,Goal) values('StoreA',50,50),('StoreB',40,50),('StoreC',25,30)
Id Store Actual Goal
1 StoreA 50 50
2 StoreB 40 50
3 StoreC 25 30
Query -
select Store, nullif(Actual,Goal) 'CheckNullIf' from Store
Output -
Store CheckNullIf
StoreA NULL
StoreB 40
StoreC 25
If both expressions values are same then return Null otherwise return first expression values.
create table Store
(
Id int identity(1,1),
Store varchar(50),
Actual int,
Goal int
)
insert into Store(Store,Actual,Goal) values('StoreA',50,50),('StoreB',40,50),('StoreC',25,30)
Id Store Actual Goal
1 StoreA 50 50
2 StoreB 40 50
3 StoreC 25 30
Query -
select Store, nullif(Actual,Goal) 'CheckNullIf' from Store
Output -
Store CheckNullIf
StoreA NULL
StoreB 40
StoreC 25