1). Handle NULL value by procedure
declare @value int=null; if @value is NULL begin Select 'Value is NULL' AS Result end set @value=1 if @value is NOT NULL begin Select 'Value is not NULL' As Result end
Example for "Temprory Table"
declare @ABC table(Col1 int, Col2 varchar(20))
insert into @ABC values(1,'Test 1')
insert into @ABC values(2,'Test 2')
insert into @ABC values(3,'Test 3')
insert into @ABC values(4,'Test 4')
insert into @ABC values(5,'Test 5')
insert into @ABC values(null,'Test 6')
insert into @ABC values(7,'Test 7')
insert into @ABC values(null,'Test 8')
insert into @ABC values(null,'Test 9')
insert into @ABC values(10,'Test 10')
--It returns 3 rows
select * from @Temp where Col1 in(1,3,6)
--It does not include null so it returns 3 rows
select * from @Temp where Col1 in(1,3,6,null)
1). Use Ascending order
select * from @Temp order by Col1;
2). -- Use descending order
select * from @ABC order order by Col1 Desc
3). Null in GroupBy
select col1 count(col2) AS from @ABC Group By Col1
4). Case expression
select CASE when name IS NULL then 'N/A' else name end from Country ---where Country is a table---
5). Using COALESCE
Select COALESCE(name, 'N/A') from Countries
6). ---Return 'N/A' if the name is NULL
Select IF(name IS NULL, 'N/A', name) from countries
About to NULL value's facts,
it is not equal to or similar as any value
it is not greater than, less than or different from any type of value The null value is not equal to NULL itself. it is not greater than, less than or different from NULL values.
Liked By
Write Answer
How can manage NULL value in SQL server ?
Join MindStick Community
You have need login or register for voting of answers or question.
Anonymous User
17-Sep-2018The different types of NULL values in Database like -
Blank value.
Empty value.
Zero value.
Optional value.
Invalid value.
void value.
Nothing value.
Missing value.
The lowest value.
Ignorable value.
1). Use Ascending order
2). -- Use descending order
3). Null in GroupBy
4). Case expression
5). Using COALESCE
6). ---Return 'N/A' if the name is NULL
About to NULL value's facts,it is not equal to or similar as any value
it is not greater than, less than or different from any type of value
The null value is not equal to NULL itself.
it is not greater than, less than or different from NULL values.