The sort method of a value similar to 1.1.1.1 in SQL Server varchar data

Source: Internet
Author: User

SELECT * FROM table name
Order BY Convert (int,left (column name, CHARINDEX ('. ', column name + '. ') -1) ASC, column name ASC

CHARINDEX ('. ', column name) query first. (dot) in the number of

CHARINDEX ('. ', column name + '. ') Give no data to the last side Add. (points) This allows the first digit to be found without a decimal point.

Left (column name, CHARINDEX ('. ', column name)) Query decimal value

Left (column name, CHARINDEX ('. ', column name + '. ')) Add one after all values.

Left (column name, CHARINDEX ('. ', column name + '. ') -1) Decrease after the value of the query one is to give back the point.

Convert (Int,left (column name, CHARINDEX ('. ', column name + '. ') -1) Take the value before the first decimal point to the INT type

Convert (Int,left (column name, CHARINDEX ('. ', column name + '. ') -1) ASC takes the value before the decimal point to the int type to be sorted (but now the sort is a bit inaccurate)

Convert (Int,left (column name, CHARINDEX ('. ', column name + '. ') -1) ASC, listing ASC so you can use the column name ASC in the back row.

The sort method of a value similar to 1.1.1.1 in SQL Server varchar data

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.