By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,806 Members | 1,787 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,806 IT Pros & Developers. It's quick & easy.

Reg sql query

P: 22
I have a SQL Table I am trying to update...I would like to add 'ABC' to the START of every value in a perticular column.

Can any one help me..

--
Sharique
Sep 30 '08 #1
Share this Question
Share on Google+
4 Replies


P: 22
before:
ANZAED12M
ANZAED1M
ANZAED1M
ANZAED2M
ANZAED2M
ANZAED3M
ANZAED3M
ANZAED6M
ANZAED6M
ANZAED9M


after:
OOOAED12M
OOOAED12M
OOOAED1M
OOOAED1M
OOOAED2M
OOOAED2M
OOOAED3M
OOOAED3M
OOOAED6M
OOOAED6M
OOOAED9M
OOOAED9M


query:

UPDATE table_name SET column=substring(column,1,start-1) || 'values' || substring(column,4,length of column) WHERE substring(column,1,3) = 'values'

UPDATE table_name SET ric=substring(ric,1,0) || 'OOO' || substring(ric,4,30) WHERE substring(ric,1,3) = 'ANZ'
Sep 30 '08 #2

ck9663
Expert 2.5K+
P: 2,878
Your query did not add the string but replace it. I believe this would be more efficient:

Expand|Select|Wrap|Line Numbers
  1. UPDATE YourTable
  2. set = replace(yourcolumn,'ANZ','OOO')
  3. where yourcolulmn like 'ANZ%'
  4.  
-- CK
Sep 30 '08 #3

P: 92
Try this:
Expand|Select|Wrap|Line Numbers
  1. UPDATE TableName SET ColumnName = 'ABC' + ColumnName 
You can research more about SQL scripting here.
Sep 30 '08 #4

P: 92
Try this:
Expand|Select|Wrap|Line Numbers
  1. UPDATE TableName SET ColumnName = 'ABC' + ColumnName 
You can research more about SQL scripting here.
Oops.. this is very late. hehe
Sep 30 '08 #5

Post your reply

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