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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 update records

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 TABLE1
SET ACCTNO='043697644'
FROM TABLE1
WHERE 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 TABLE1
SET ACCTNO='0' + ACCTNO
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-04-06 : 11:40:26
What data type is AcctNo?

--
Gail Shaw
SQL Server MVP
Go to Top of Page

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 Shaw
SQL Server MVP

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-04-06 : 12:02:56
UPDATE TABLE1
SET ACCTNO='0' + ACCTNO
WHERE LEN(ACCTNO)<10
Go to Top of Page

ntn104
Posting Yak Master

175 Posts

Posted - 2011-04-06 : 12:09:49
Thank you! that works perfectly...

quote:
Originally posted by robvolk

UPDATE TABLE1
SET ACCTNO='0' + ACCTNO
WHERE LEN(ACCTNO)<10

Go to Top of Page
   

- Advertisement -