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 |
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2010-02-10 : 08:47:07
|
| how can i update all records that are only 2 digits I want to add a 0 in front of them (this is a varchar field)so 123 will stay 123 but 12 will turn to 012? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-10 : 08:49:35
|
| [code]UPDATE YourTableSET yourcol=RIGHT('0' + yourcol,3)[/code]------------------------------------------------------------------------------------------------------SQL Server MVP |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-10 : 08:50:26
|
or UPDATE YourTableSET yourcol='0' + yourcolWHERE LEN(yourcol)=2 ------------------------------------------------------------------------------------------------------SQL Server MVP |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-10 : 09:25:00
|
quote: Originally posted by esthera how can i update all records that are only 2 digits I want to add a 0 in front of them (this is a varchar field)so 123 will stay 123 but 12 will turn to 012?
If you use front end application, do formation thereMadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-10 : 09:26:05
|
quote: Originally posted by visakh16 or UPDATE YourTableSET yourcol='0' + yourcolWHERE LEN(yourcol)=2 ------------------------------------------------------------------------------------------------------SQL Server MVP
orUPDATE YourTableSET yourcol=replace(str(yourcol,3),' ','0')MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|