SQL generates auto-sequence numbers with placeholders (masks) that can adjust the placeholder length of the statement

Source: Internet
Author: User

MSSQL statement

--Declaring variables
DECLARE @i int
DECLARE @xh varchar (10)
DECLARE @name varchar (10)
Set @i = 0

--Start the loop to insert the data
While @i < 100
BEGIN

                       
SET @xh = Right ('000000' + CAST (@i as varchar),6)-- number of mask bits
Set @name = ' info ' + CAST (@i as varchar (10))
--print @xh
INSERT into qwe values (@xh, @name, @i)
Set @i [email protected] +1
END

PS: Can change the mask and mask the number of bits to adjust appropriately

Execution effect

000000 Information 0 0
000001 Information 11
000002 Information 22
000003 Information 33
000004 Information 44
000005 Information 55
000006 Information 66
000007 Information 77
000008 Information 88
000009 Information 99
000010 Information 1010
000011 Information 1111
000012 Information 1212
000013 Information 1313
000014 Information 1414
000015 Information 1515
000016 Information 1616
000017 Information 1717
000018 Information 1818
000019 Information 1919
000020 Information 2020
000021 Information 2121
000022 Information 2222
000023 Information 2323
000024 Information 2424
000025 Information 2525
000026 Information 2626
000027 Information 2727
000028 Information 2828
000029 Information 2929
000030 Information 3030
000031 Information 3131
000032 Information 3232
000033 Information 3333
000034 Information 3434
000035 Information 3535
000036 Information 3636
000037 Information 3737
000038 Information 3838
000039 Information 3939
000040 Information 4040
000041 Information 4141
000042 Information 4242
000043 Information 4343
000044 Information 4444
000045 Information 4545
000046 Information 4646
000047 Information 4747
000048 Information 4848
000049 Information 4949
000050 Information 5050
000051 Information 5151
000052 Information 5252
000053 Information 5353
000054 Information 5454
000055 Information 5555
000056 Information 5656
000057 Information 5757
000058 Information 5858
000059 Information 5959
000060 Information 6060
000061 Information 6161
000062 Information 6262
000063 Information 6363
000064 Information 6464
000065 Information 6565
000066 Information 6666
000067 Information 6767
000068 Information 6868
000069 Information 6969
000070 Information 7070
000071 Information 7171
000072 Information 7272
000073 Information 7373
000074 Information 7474
000075 Information 7575
000076 Information 7676
000077 Information 7777
000078 Information 7878
000079 Information 7979
000080 information 8080
000081 Information 8181
000082 Information 8282
000083 Information 8383
000084 Information 8484
000085 Information 8585
000086 Information 8686
000087 Information 8787
000088 Information 8888
000089 Information 8989
000090 Information 9090
000091 Information 9191
000092 Information 9292
000093 Information 9393
000094 Information 9494
000095 Information 9595
000096 Information 9696
000097 Information 9797
000098 Information 9898
000099 Information 9999

SQL generates auto-sequence numbers with placeholders (masks) that can adjust the placeholder length of the statement

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.