Formatting result in SQL display '000025' instead of 25

2

I have a table with the following structure:

ID          MONTH
21714       JAN
76101       JAN
175187      FEB
243575      APR
299116      JUN
304742      JUN

I need to generate a string of 14 characters for each record similar to 'ABC00000000000' , mixing mes and id , and placing 0 's between them:

ID          MONTH   ALIAS
21714       JAN     JAN00000021714
76101       JAN     JAN00000076101
119024      JAN     JAN00000119024
175187      FEB     FEB00000175187
243575      APR     APR00000243575
299116      JUN     JUN00000299116
304742      JUN     JUN00000304742
    
asked by ProMas 12.10.2017 в 17:21
source

1 answer

3

Use the following:

SELECT ID, MONTH, MONTH + RIGHT('000000000000000'+ISNULL(ID,''), 14) AS 'Alias'
FROM Tabla

Greetings.

    
answered by 12.10.2017 в 17:26