Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace Statement, How to remove unwanted characters

Status
Not open for further replies.

daguas

Technical User
Jul 8, 2004
24
0
0
US
Using SQL2005
I have an application that was adding zeros to a nvarchar field, we have corrected the applications behavior, but I need to delete these zeros in existing records. I can select the records to update using the following
Select *
From dbo.Contracts
Where dbo.ContractNumber Like ('%O002')

I need to remove the 00 from between the letter O and the number 2 "O002"

I know its a replace statment, but need help with the syntax.

THanks
 
In your case you would need to look at STUFF() function.
 
In case of always 2 characters, you can try

set @ddd = 'ABDCO002RDDB00'

select STUFF(@ddd, CHARINDEX('O',@ddd,1)+1,2,'')
 
Code:
update dbo.Contracts
set ContractNumber=replace(ContractNumber,'O002','O2')
Where ContractNumber Like ('%O002')
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top