How to compensate '0', and guarantee 5-bit method

xiaoxiao2021-03-06  54

- Declare integer variable @i

Declare @i int

- Value Value Set @ i = 16

- Method 1: Type conversion to characters, add 4 '0' in front, 5 Select Right ('0000' CAST (@i as varchar), 5) from the right

- Method 2: A front plus 5-len (@i space, turn the space to '0'select replace (Space (5-len (@i)) Cast (@i as varchar),' ',' 0 ')

- Method 3: Add a large number to the variable (5 after this number satisfied 0), 5 from the right

SELECT RIGHT (1000000 @ i, 5)

- Method 4: Method 2 Thoughts SELECT Replace (Space (5-LEN (@i)), '', '0') Cast (@i as varchar)

转载请注明原文地址:https://www.9cbs.com/read-114976.html

New Post(0)