SQL Server Format String plus front 0 or front 0

Source: Internet
Author: User
Looking for a ready-made function, I found that SQL Server users are lazy than me, and I don't even have this basic function! Good, because all I need is the serial number and it will be reset every month, and the maximum ordinal number will not exceed 0.1 million. So use Ribao: declare @ SNintdeclare @ SNLenintset @ SNLen5set @ SN1selectright (0

Looking for a ready-made function, I found that the SQL Server writer is lazy than me, and I don't even have this basic function! Good, because all I need is the serial number and it will be reset every month, and the maximum ordinal number will not exceed 0.1 million. So use rigoal: declare @ SN int declare @ SNLen int set @ SNLen = 5 set @ SN = 1 select right ('0

Looking for a ready-made function, I found that the SQL Server writer is lazy than me, and I don't even have this basic function!

Good, because all I need is the serial number and it will be reset every month, and the maximum ordinal number will not exceed 0.1 million. So use rigth:

Declare @ SN int

Declare @ SNLen int

Set @ SNLen = 5

Set @ SN = 1

Select right ('20140901' + cast (@ SN as varchar (10), @ SNLen)

Set @ SN = 333

Select right ('20140901' + cast (@ SN as varchar (10), @ SNLen)

Set @ SN = 55555

Select right ('20140901' + cast (@ SN as varchar (10), @ SNLen)

These codes may be related:

Declare @ OfYear nvarchar (4)

Declare @ OfMonth nvarchar (2)

Set @ OfYear = datename (yyyy, @ DateTime)

Set @ OfMonth = datename (mm, @ DateTime)

Yes, right

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.