473,386 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Updating Character String with sql

Hi,


Help needed please.

Basically I am wanting to update a 16 digit character string which is in a table called say accounts.

If the account no. field is say 0502562389568745 I want to amend every record by taking away the leading zero of the account no. and replace it with a 9.

So the result would be 9502562389568745 and I want to run this so that it will update every account no. in the accounts table.

I know its an update statement but wasn't sure how to pull the first character in the string out and whether I used the replace statement as well?!

I am new to sql and have been trawling the net and books for answers but come up with nothing as yet so any help would be amazing!!!

Thanks

Graeme
Nov 8 '07 #1
3 3053
iburyak
1,017 Expert 512MB
Try this:
Expand|Select|Wrap|Line Numbers
  1.  
  2. update accounts
  3. set [account no] = '9' + substring([account no],2,100)
  4. where substring([account no],1,1) = '0'
Good Luck
Nov 8 '07 #2
ck9663
2,878 Expert 2GB
Try this:
Expand|Select|Wrap|Line Numbers
  1.  
  2. update accounts
  3. set [account no] = '9' + substring([account no],2,100)
  4. where substring([account no],1,1) = '0'
Good Luck

note:
this will only replace if the first digit is '0' and will only replace the first digit. if you're expecting 2 or more '0'-prefix, you're going to do some coding for that one...
Nov 9 '07 #3
Thanks for the help guys.


That was hugely useful!!!!


G
Nov 9 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Hal Vaughan | last post by:
First, I am aware of both SwingUtilities.invokeLater(), and of using Thread to create a new thread.  These are part of the problem. I want to have something running in the background, while the...
9
by: refer_to_website | last post by:
My VB.NET web application has a textbox where the user is allowed to enter up to 50 characters. I have a label on the form next to the textbox that tells the user how many remaining characters he...
0
by: cwbp17 | last post by:
Have two tables that have a FK relationship on ID column. Have one datagrid that displays all of the columns of both tables. What's the best approach on updating a row from the datagrid back to...
1
by: vanisathish | last post by:
Hi, Currently we are updating the html page contents, some text boxes using javascript. Is it possible to update the same from am activeX dll. And in javascript, will there be any impact on...
0
by: cwbp17 | last post by:
I'm having trouble updating individual datagrid cells. Have two tables car_master (columns include Car_ID, YEAR,VEHICLE) and car_detail (columns include Car_ID,PRICE,MILEAGE,and BODY);both tables...
14
by: el_sid | last post by:
Our developers have experienced a problem with updating Web References in Visual Studio.NET 2003. Normally, when a web service class (.asmx) is created, updating the Web Reference will...
4
by: Geoff | last post by:
Hi I'm hoping somebody can help me with the following problem that has occurred to me. Suppose I have two tables in an SQL Server database. Let's call these tables A and B. Assume that A has...
15
by: sara | last post by:
I have a Memo field in a table to hold notes from a conversation a social worker has had with a client (this is for a non-profit). If the user needs to update the memo field, I need to find the...
20
by: Xcriber51 | last post by:
Hi -- I'm not entirely familiar with the norms and standard libraries of JavaScript so if the answer to this is yesterday's news, please ignore. I'm trying to write a simple text formatting...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.