Casewhen returns an empty string to 0.

Source: Internet
Author: User
Note: If the field is of the varchar type, the conditions after the when must be enclosed by the quotation mark SELECT (CASEmarital_statusWHEN0THEN married WHEN1THEN unassociated ELSEWEIZHIEND) using the preceding statement. If the marital_status is null

Note: If the field is of the varchar type, the condition after when must be enclosed by the quotation mark SELECT (CASE marital_status WHEN 0 THEN married WHEN 1 THEN unmarried else weizhi end) AS marital_status FROM tj_archive WHERE id = D1407280006 use the preceding statement. If marital_status is an empty string (instead of null)

Note: If the field is of the varchar type, quotation marks are required for the condition after when.
SELECT (CASE 'marate_status' WHEN 0 then' married 'when 1 then' unmarried 'else' weizhi' END) AS marital_status FROM tj_archive WHERE id = 'd1407280006'

In the preceding statement, if marital_status is a null string instead of null, the query result is "married"

Finally, the correct result is:

SELECT (CASE 'marital _ status' WHEN '0' then' married 'when' 1 'then' unassociated 'else' weizhi' END) AS marital_status FROM tj_archive WHERE id = 'd1407280006'

The red part is a different sentence.

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.