SQL formatting field

Asked

Viewed 42 times

0

I have the following structure:

|VALOR|
|  1  |
|  23 |
|  5  |
|  41 |

I have a need to transform:

| VALOR |
|  0001 |
|  0023 |
|  0005 |
|  0041 |

Is there any function I can do that?

  • 1

    FORMAT(value, '0000')

2 answers

2


If the field is char:

Select REPLICATE('0', 4 - LEN('23')) + RTrim('23')

2

Browser other questions tagged

You are not signed in. Login or sign up in order to post.