Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Add prefix '0' to the column value
Message
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Add prefix '0' to the column value
Miscellaneous
Thread ID:
01654668
Message ID:
01654668
Views:
55
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
Next
Reply
Map
View

Click here to load this message in the networking platform