Solved

SQL REPLACE Statement

Posted on 2008-10-07
5
432 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

752 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