Introduction
There are three ways in which we can remove Null values in Table data and show them to the user.
StepsCreate one table.
Then, enter some dummy records.
Replace the Null value using ISNULL() function.
Replace the Null value using COALESCE() function() function.
Replace the Null value using CASE statement.
There are three ways in which we can remove Null values in Table data and show them to the user.
DescriptionIn our Table data, some columns contain null values. We can replace it using ISNULL() function , COALESCE() function, and CASE Statement.
StepsCreate one table.
- CREATE TABLE [dbo].[tblEmployees](
- [Id] [int] IDENTITY(1,1) NOT NULL,
- [Name] [nvarchar](50) NULL,
- [Gender] [nvarchar](10) NULL,
- [Salary] [int] NULL,
- PRIMARY KEY CLUSTERED
- (
- [Id] ASC
- )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY]
- GO
Replace the Null value using ISNULL() function.
- SELECT E.Name as Employee, ISNULL(M.Gender,'No Gender') as Gender
- FROM tblEmployees E
- LEFT JOIN tblEmployees M
- ON E.Id = M.Id
Replace the Null value using COALESCE() function() function.
- SELECT E.Name as Employee, COALESCE(M.Gender,'No Gender') as Gender
- FROM tblEmployees E
- LEFT JOIN tblEmployees M
- ON E.Id = M.Id
Replace the Null value using CASE statement.
- SELECT E.Name as Employee, CASE WHEN M.Gender IS NULL THEN 'No Gender'
- ELSE M.Gender END as Gender
- FROM tblEmployees E
- LEFT JOIN tblEmployees M
- ON E.Id = M.Id
No comments:
Post a Comment