Sort by the first letter of Chinese characters (SQL statement) only for collection, I copy and paste

Source: Internet
Author: User

In SQL server, you can use SQL statements to sort by the first letter of a Chinese character. For example, we often use "sort by the first letter of a name"

-- Replace tableName and colName with your own.
-- Press pinyin

Alter table tableName
Alter column colName nvarchar (100) COLLATE Chinese_PRC_CI_AS
Select * from tableName order by colName

-- Stroke
Alter table tableName
Alter column colName nvarchar (100) COLLATE Chinese_PRC_Stroke_CI_AS
Select * from tableName order by colName

Note:

ALTER: modify a table

Collate: a clause that can be applied to database or column definitions to define sorting rules, or to string expressions to apply sorting rule projection.

Chinese_PRC_CI_AS: An SQL sorting rule

The following describes the sorting rules:

What is a sorting rule? MS is described as follows: "in SQL Server,

The physical storage of strings is controlled by sorting rules. Sorting rules specify the bit mode and storage of each character

Rules Used for saving and comparing characters.

Run the following statement in the query analyzer to obtain all the sorting rules supported by SQL SERVER.

Select * from: fn_helpcollations () // SQL server has 1011 sorting rules

The name of a sorting rule consists of two parts. The first half is the character set supported by this sorting rule.
For example:
Chinese_prc_cs_ai_ws

First half: the Unicode character set. The chinese_prc _ pointer sorts Unicode in simplified Chinese characters.

The second half of the sorting rule is the suffix meaning:

_ Bin binary sorting
_ Ci (CS) is case sensitive, CI is case insensitive, and CS is case sensitive
_ Whether AI (AS) distinguishes stress, AI does not distinguish,
_ KI (KS) indicates whether Kana is distinguished. Ki is not distinguished, and KS is distinguished.
_ Whether wi (WS) is differentiated by width WI and WS

Case Sensitive: select this option if you want to make the comparison between uppercase and lowercase letters different.

Accent differentiation: select this option if you want to treat the comparison as different from the accent and non-accent letters. If this option is selected,
Comparison also treats letters with different accents as unequal.

Kana differentiation: select this option if you want to treat Katakana and katakana as different Japanese syllables.

Width differentiation: select this option if you want to make the comparison between halfwidth and fullwidth characters.

Extended reading: C # getting the first letter of a Chinese character

// ============= Query by letter

Select PM from auto_car_brand group by PM
Having PM like '[A-Za-Z]'

 

 

 

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.