Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
rcr69er
Constraint Violating Yak Guru
327 Posts |
Posted - 2009-12-03 : 07:11:29
|
| Hi GuysJust a quick question.How do I place a leading 0 in front of a single digit number?So 7891011Becomes0708091011Thanks |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-12-03 : 07:20:59
|
| Hi try this once,select right('0'+column,2) from table |
 |
|
|
rajdaksha
Aged Yak Warrior
595 Posts |
Posted - 2009-12-03 : 07:27:26
|
| HiColumn datatype int means it won't work rightselect right('0'+6,2) select right('0'+'6',2)-------------------------R... |
 |
|
|
creieru
Starting Member
12 Posts |
Posted - 2009-12-03 : 07:27:47
|
| select right('0'+@str, 2), where @str is your number converted to varchar |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-12-03 : 07:28:17
|
| SELECT CASE WHEN LEN(id) < 2 THEN '0'+id ELSE id END,LEN(id)FROM (SELECT CAST(4 AS VARCHAR(32)) AS id UNION ALL SELECT CAST(11 AS VARCHAR(32)))s |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-12-03 : 07:59:48
|
quote: Originally posted by rcr69er Hi GuysJust a quick question.How do I place a leading 0 in front of a single digit number?So 7891011Becomes0708091011Thanks
Where do you want to show formatted data?MadhivananFailing to plan is Planning to fail |
 |
|
|
stepson
Aged Yak Warrior
545 Posts |
Posted - 2009-12-04 : 02:26:01
|
| SELECT CASE WHEN LEN(id) < 2 THEN REPLACE(STR(id, 2), ' ', '0')ELSE id ENDFROM ... |
 |
|
|
|
|
|