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 2000 Forums
 Transact-SQL (2000)
 Update Syntax

Author  Topic 

kathyc2003
Starting Member

15 Posts

Posted - 2006-11-02 : 11:19:32
I need to write an update statement that replaces AccountNumber's that
contain "* *" with "*".

Below is the select statement that displays the rows, but I can't figure out how to wrap the update statement around it.

SELECT Name, SUBSTRING(AccountNumber, 1, LEN(AccountNumber))
FROM dbo.AccountBase
WHERE AccountNumber IS NOT NULL
AND AccountNumber LIKE '%* *%'
ORDER BY Name ASC;

Thank you.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-11-02 : 11:29:46
[code]
update a
set AccountNumber = replace(AccountNumber, '* *', '*')
from dbo.AccountBase a
WHERE AccountNumber IS NOT NULL
AND
AccountNumber LIKE '%* *%'
[/code]


KH

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-11-02 : 12:06:39
"AccountNumber IS NOT NULL AND"

Bit redundant, Old Boy!

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-11-02 : 20:21:02
>>SUBSTRING(AccountNumber, 1, LEN(AccountNumber))

Isnt this equal to AccountNumber?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -