如何检查 SQL Server 日期时间列是否为空?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4546457/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 08:41:56  来源:igfitidea点击:

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

sqlsql-serverdatetime

提问by Vahid

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

如何检查 SQL Server 日期时间列是否为空?

回答by Oded

Test it with IS NULL.

IS NULL.

If using .NET, test against DBNULL.

如果使用 .NET,请针对DBNULL.

回答by David

... WHERE [ColumnName] IS NULL

... WHERE [ColumnName] IS NULL

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

或者你的意思是“空”不是NULL什么?您的列是否允许NULL值?您是否正在寻找某种默认值?

回答by Klaus Byskov Pedersen

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

要获取带有空日期时间列的所有行,您可以执行以下操作:

SELECT * FROM yourtable WHERE yourdatecolumn IS NULL

回答by Ans Bilal

This worked for me in C# , Where

这在 C# 中对我有用,在哪里

conis my Sql Connection

con是我的 Sql 连接

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

回答by Antony Fuentes Artavia

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

作为使用 NULL 的替代方法,您可以尝试:

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

回答by David

net Use IsDBNull or in transact sql use is null.

net 使用 IsDBNull 或在事务 sql 中使用为 null。