Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Add prefix '0' to the column value
Message
De
29/09/2017 12:30:19
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Add prefix '0' to the column value
Divers
Thread ID:
01654668
Message ID:
01654668
Vues:
56
Hi,

A customer asked me to pad the ID field with leading zeroes up to 4 digits in total. The field is a character type. Here are some examples of how they appear:
'355'
'33'
'9938'
'056'
The have to become:
'0355'
'0033'
'9938'
'0056'
The trick is that some values are not numbers but combination of numbers and letters. For example:
'002-ABCD'
which should become:
'0002-ABCD'
How do I do it in T-SQL in one UPDATE?

TIA
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform