如何检查SQL Server datetime列是否为空?

时间:2022-04-26 07:13:15

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

如何检查SQL Server datetime列是否为空?

6 个解决方案

#1


17  

Test it with IS NULL.

用IS NULL测试它。

If using .NET, test against DBNULL.

如果使用.NET,请对DBNULL进行测试。

#2


9  

... WHERE [ColumnName] IS NULL

... WHERE [ColumnName]为空

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?

或者你的意思是“空”不是NULL的其他东西?您的列是否允许NULL值?您是在寻找某种默认值吗?

#3


5  

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

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

SELECT * FROM yourtable WHERE yourdatecolumn IS NULL

#4


1  

This worked for me in C# , Where

这在C#中适用于我,其中

con is my Sql Connection

con是我的Sql连接

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

#5


0  

net Use IsDBNull or in transact sql use is null.

net使用IsDBNull或在transact sql中使用为null。

#6


0  

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

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

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

#1


17  

Test it with IS NULL.

用IS NULL测试它。

If using .NET, test against DBNULL.

如果使用.NET,请对DBNULL进行测试。

#2


9  

... WHERE [ColumnName] IS NULL

... WHERE [ColumnName]为空

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?

或者你的意思是“空”不是NULL的其他东西?您的列是否允许NULL值?您是在寻找某种默认值吗?

#3


5  

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

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

SELECT * FROM yourtable WHERE yourdatecolumn IS NULL

#4


1  

This worked for me in C# , Where

这在C#中适用于我,其中

con is my Sql Connection

con是我的Sql连接

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

#5


0  

net Use IsDBNull or in transact sql use is null.

net使用IsDBNull或在transact sql中使用为null。

#6


0  

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

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

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