Solved

SQL REPLACE Statement

Posted on 2008-10-07
5
417 Views
Last Modified: 2011-10-03
Hi,

I am trying to update a Column within a Table:

all records in column are in following format:

99-xxx-xxxx
89-xxx-xxxx
99-xxx-xxxx

I just want to update first two char '99' to '89' and rest of '-xxx-xxxx' remain intact.

Thank you in advance.

CN
0
Comment
Question by:CyberNerd
  • 4
5 Comments
 
LVL 38

Expert Comment

by:Jim P.
ID: 22664306
Update MyTable
SET MyCol = '99' + SUBSTR(MyCol, 3, 15)
WHERE Left(MyCol,2) = '89'
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 22664315
Bqckwards
Update MyTable
SET MyCol = '89' + SUBSTR(MyCol, 3, 15)
WHERE Left(MyCol,2) = '99'

Open in new window

0
 
LVL 2

Author Comment

by:CyberNerd
ID: 22664393
I've ran the update statement but I get the following error:

Msg 195, Level 15, State 10, Line 2
'SUBSTR' is not a recognized built-in function name.

Is this mean SUBSTR is not enabled in my SQL 2005 server?
0
 
LVL 38

Accepted Solution

by:
Jim P. earned 125 total points
ID: 22664514
Try substring. SUBSTR is an accepted synonym in Oracle. My bad.
Update MyTable
SET MyCol = '89' + substring(MyCol, 3, 15)
WHERE Left(MyCol,2) = '99'

Open in new window

0
 
LVL 38

Expert Comment

by:Jim P.
ID: 22664870
Glad to be of assistance. May all your days get brighter and brighter.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now