A summary of time-empty processing in SQL Server _mssql

Source: Internet
Author: User
Several main situations are summarized:
First, how to enter a null value
If you do not enter a null value, when the time is empty, the default is written to "1900-01-01", which is cumbersome for business processing.
Ctrl+0 You can enter a null value.
Second, the time field how to judge Null in the SQL statement
Suppose the table is: TestTable
SN DateTime1 DateTime2
1 2011-10-24 2011-10-25
2 NULL 2011-10-26
3 2011-10-25 NULL
Use case to query, if written:
Select (Case DateTime1 when NULL then ' a ' else ' B ' ") from TestTable
The result of the query is:

B

This is clearly not the desired result;
Select (Case DateTime1 when DateTime1 then ' B ' else ' a ') from TestTable
Its query results are:

A

This is the result of the want.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.