How do I chec开发者_JS百科k if a SQL Server datetime column is empty?
Test it with IS NULL
.
If using .NET, test against DBNULL
.
... 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?
To get all rows wtih an empty datetime column you could do this:
SELECT * FROM yourtable WHERE yourdatecolumn IS NULL
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);
net Use IsDBNull or in transact sql use is null.
Just as an alternative to using NULL, you could try:
SELECT * FROM table_name WHERE column_name = '0000-00-00'
精彩评论