sqlserver 中时间为空的处理小结
Jun 07, 2016 pm 06:02 PM
sql
sql server中常常需要使用DateTime类型的字段。当此类型字段值为空时,常常出现各种异常
现将几种主要情况进行小结:一、如何输入NULL值
如果不输入null值,当时间为空时,会默认写入"1900-01-01",在业务处理时很麻烦。
ctrl+0即可输入NULL值。
二、如何在sql语句中判断为NULL的时间字段
假设表为:TestTable
SN DateTime1 DateTime2
1 2011-10-24 2011-10-25
2 NULL 2011-10-26
3 2011-10-25 NULL
用case进行查询,若写成:
select (case DateTime1 when NULL then 'a' else 'b' end) from TestTable
则查询结果为:
b
这显然不是想要的结果;需要写成:
select (case DateTime1 when DateTime1 then 'b' else 'a' end) from TestTable
其查询结果才为:
a
这才是想要的结果。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
Two Point Museum: Bungle Wasteland Location Guide
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Two Point Museum: Bungle Wasteland Location Guide
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What is the difference between HQL and SQL in Hibernate framework?

Usage of division operation in Oracle SQL

What does the identity attribute in SQL mean?

Comparison and differences of SQL syntax between Oracle and DB2

How does Java use the MySQL driver interceptor to implement SQL time-consuming calculations?

Detailed explanation of the Set tag function in MyBatis dynamic SQL tags

How SpringBoot encrypts the SQL account password of the configuration file
