Reputation: 3135
If I have the following example table, is there any way that I only keep rows where the "Closed Date" column is empty? In this example, only the second row has an empty "Closed Date" column, the third and fourth are not.
Unique Key,Created Date,Month,Closed Date,Latitude,Longitude
32098276,12/1/2015 0:35,12,,40.78529363,-73.96933478,"(40.78529363449518, -73.96933477605721)"
32096105,11/30/2015 20:09,11,11/30/2015 20:09,40.62615508,-73.9606431,"(40.626155084398036, -73.96064310416676)"
32098405,11/30/2015 20:08,11,11/30/2015 20:08,40.6236074,-73.95914964,"(40.62360739765128, -73.95914964173129)"
I find this but this is not exactly I am looking for. Could any guru enlighten? Thanks!
return empty row based on condition in sql server
Upvotes: 2
Views: 21402
Reputation: 1746
Another approach for SQL Server to include empty string ('')
-->> SQL Server
SELECT * FROM your_table
WHERE [Closed Date] IS NULL OR [Closed Date] = ''
SELECT *
FROM your_table
WHERE ISNULL([Closed Date],'') = ''
Upvotes: 1
Reputation: 7736
SELECT *
FROM your_table
WHERE [Closed Date] IS NULL OR LTRIM(RTRIM([Closed Date])) = ''
Upvotes: 4
Reputation: 521168
You can use the IS NULL
condition in a WHERE
clause:
SELECT *
FROM your_table
WHERE "Closed Date" IS NULL
Upvotes: 2
Reputation: 175646
You can use IS NULL
to filter out records that contains NULL
value:
SELECT *
FROM your_table
WHERE "Closed Date" IS NULL
Keep in mind that column identifier with space is bad practice. You should use something like Closed_Date
to avoid quoting.
Upvotes: 2