SQL Server Case Sensitive query

Source: Internet
Author: User

SQL Server defaults to case-insensitive queries, but sometimes some query statements require a case-sensitive query, which requires some special handling. There are two main ways of distinguishing between case and case.

Turn binary judgment

SELECT * FROM table where CAST (name as varbinary) =cast (' Liyuanba ' as varbinary)               -Short String select * from table where CAST (n Ame as varbinary) =cast (' Liyuanbaabcedef ... ' as varbinary (500))--long string

Attention

varbinary default length is 30, if the length is not enough to keep out of the part, resulting in a judgment error!

By Collate Chinese_prc_cs_as

SELECT * FROM table where name collate chinese_prc_cs_as= ' Liyuanba '        --exact select * from table where name collate Chinese _prc_cs_as like ' liyuanba% '  --Blur

Advantages
It is recommended that you do not need to consider string length issues.

SQL Server Case Sensitive query

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.