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 letters by 0 (zeros)

Status
Not open for further replies.
Nov 29, 2002
64
0
0
US
Hello there, thanks for the previous responses. Is it there an easy way to replace one character of a field by 0 (zero) using just SQL?

For example:
TXN_AMT
000024584862R
000000473929J
000000012929A
000005013141S

to
TXN_AMT
0000245848620
0000004739290
0000000129290
0000050131410

The length of the field is allways 13, and the letter to replace is allways the last character on the right.
cheers,
Alfredo
 
to retrieve only,
Code:
select left(yourfield,12)&'0' 
  from yourtable
to make it permanent,
Code:
update yourtable
   set yourfield = left(yourfield,12)&'0'
you did not say so, but if the 13th position can sometimes contain numerics, then obvioulsy you'd want to IIF the above statements

rudy | r937.com | Ask the Expert | Premium SQL Articles
SQL for Database-Driven Web Sites (next course starts May 8 2005)
 
I believe it'd be something like

Replace(Right([yourfield], 1), "0")

-------------------------
Just call me Captain Awesome.
 
I believe it'd be something like

Replace(Right([yourfield], 1), "0")

-------------------------
Just call me Captain Awesome.
 
R937,

Thanks a lot for your response. It includes sometimes numbers, indeed.

cheers,

Alfredo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top