On the technique of using SQL statements to implement a string of digits less than 0 on the left

Source: Internet
Author: User

When we use SQL to do query insertion, we usually use SQL to query a string number, which is made up of numbers. In order to unify the aesthetics, we record the number, the uniform specified number of digits, the number of bits we left 0. If the number 66, we specify the number of digits is 5, the saved data should be 00066. How should such an operation be implemented in SQL?

First, the query statement: Right (' 0000 ' +cast (' 123 ' as nvarchar (50)), 4)

Statement interpretation: Formula right (' Bits ' +cast (field to be judged as nvarchar (50)), number of digits)

PS: The above query statement is placed in the Select, the query result is to judge all the fields to the left 0 processing.

Example: Querying the user table for all user numbers, and the number of 5-bit 0 processing

User table:

Query statements and results:

On the technique of using SQL statements to implement a string of digits less than 0 on the left

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.