Vahid
Vahid

Reputation: 251

How do I check if a SQL Server datetime column is empty?

How do I check if a SQL Server datetime column is empty?

Upvotes: 25

Views: 102146

Answers (6)

Antony Fuentes
Antony Fuentes

Reputation: 1103

Just as an alternative to using NULL, you could try:

SELECT * FROM table_name WHERE column_name = '0000-00-00'

Upvotes: 0

Ans Bilal
Ans Bilal

Reputation: 1067

This worked for me in C# , Where

con is my Sql Connection

SqlCommand cmd = new SqlCommand("Select * From Transactions WHERE TransactionID = '"+tid+ "'AND InDate IS NULL ", con);

Upvotes: 2

David
David

Reputation: 550

net Use IsDBNull or in transact sql use is null.

Upvotes: 0

David
David

Reputation: 218808

... WHERE [ColumnName] IS NULL

Or do you mean something else by "empty" that isn't NULL? Does your column allow NULL values? Are you instead looking for some kind of default value?

Upvotes: 15

Oded
Oded

Reputation: 498934

Test it with IS NULL.

If using .NET, test against DBNULL.

Upvotes: 30

Klaus Byskov Pedersen
Klaus Byskov Pedersen

Reputation: 120917

To get all rows wtih an empty datetime column you could do this:

SELECT * FROM yourtable WHERE yourdatecolumn IS NULL

Upvotes: 6

Related Questions