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 |
|
ntn104
Posting Yak Master
175 Posts |
Posted - 2011-04-06 : 11:30:43
|
| Is there a quick way to write update sql statement to add a number ZERO in front of account numbers. I was able to update single account, but i don't know how to write statement to update all in once..UPDATE TABLE1SET ACCTNO='043697644'FROM TABLE1WHERE ACCTNO='43697644'But I have 200 accounts that need to add leading 0 in front of these accounts). Please advise! thanks, |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-04-06 : 11:35:26
|
| UPDATE TABLE1SET ACCTNO='0' + ACCTNO |
 |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-04-06 : 11:40:26
|
| What data type is AcctNo?--Gail ShawSQL Server MVP |
 |
|
|
ntn104
Posting Yak Master
175 Posts |
Posted - 2011-04-06 : 11:41:29
|
quote: Originally posted by GilaMonster What data type is AcctNo? VARCHAR(11)I wonder if we can write case or if statement to update...if acctno <10 then add zero in front?thanks--Gail ShawSQL Server MVP
|
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-04-06 : 12:02:56
|
| UPDATE TABLE1SET ACCTNO='0' + ACCTNOWHERE LEN(ACCTNO)<10 |
 |
|
|
ntn104
Posting Yak Master
175 Posts |
Posted - 2011-04-06 : 12:09:49
|
Thank you! that works perfectly...quote: Originally posted by robvolk UPDATE TABLE1SET ACCTNO='0' + ACCTNOWHERE LEN(ACCTNO)<10
|
 |
|
|
|
|
|