TechBrothersIT is the blog spot and a video (Youtube) Channel to learn and share Information, scenarios, real time examples about SQL Server, Transact-SQL (TSQL), SQL Server Database Administration (SQL DBA), Business Intelligence (BI), SQL Server Integration Services (SSIS), SQL Server Reporting Services (SSRS), Data Warehouse (DWH) Concepts, Microsoft Dynamics AX, Microsoft Dynamics Lifecycle Services and all other different Microsoft Technologies.
How to filter Rows with Null Values in Select Statement in SQL Server - SQL Server / TSQL Tutorial Part 110
Scenario:
Let's say that you are working as SQL Server developer. You need to write two queries
1) Return all the records from dbo.Customer table where Address column has Null values
2) Return only the records from dbo.Customer table where Address column has the values other than Null.
Solution :
We can use Where clause in our Select statement to return null records or not null records. Let's create dbo.Customer table first and insert couple of records.
--Create dbo.Customer tableCreatetable dbo.Customer(
Id int,
Name VARCHAR(100),
Address VARCHAR(100))
--Insert records in dbo.Customer tableInsertinto dbo.Customer
Values(1,'Aamir','XyZ Address')
,(2,'Raza',Null)
--Return all records from dbo.Custoemr TableSelect * From dbo.Customer
Return all records from a table by using Select statement in SQL Server Database - SQL Server / TSQL Tutorial
1) Now if we want to get all the records where Address column has Null values. our query will be like below.
Select * From dbo.Customer
where Address is Null
How to get records with Null values in Select query in SQL Server Database - SQL Server / TSQL Tutorial
2) If we want to get the records where Address column has values beside Null, we will be using below query.
Select * From dbo.Customer
where Address isnot Null
Get all the records from table where column has the value beside Null values in SQL Server Database
No comments:
Post a Comment