Solved

Replace string in a record

Posted on 2014-11-12
4
156 Views
Last Modified: 2014-11-12
I need to replace the string values  ([ILS-1] CALL: 22-03-18 SPD CALL)  starting in position 15  that is 32 long with the word CALL:
I need to replace the word NORMAL with string  1,1

BEFORE
VMPIC 22:03:18 [ILS-1] CALL: 22-03-18 SPD CALL 71731,9053,9511,NORMAL,11-Nov-2014,21:55:41,21:55:41,22:03:18
VMPIC 22:03:30 [ILS-1] CALL: 22-03-30 SPD CALL 71732,9086,9509,NORMAL,11-Nov-2014,22:01:17,22:01:37,22:03:30

AFTER
VMPIC 22:03:18 CALL: 71731,9053,9511,1,1,11-Nov-2014,21:55:41,21:55:41,22:03:18
VMPIC 22:03:30 CALL: 71732,9086,9509,1,1,11-Nov-2014,22:01:17,22:01:37,22:03:30
0
Comment
Question by:thayduck
[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
  • 2
  • 2
4 Comments
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40437902
It's actually at position 16.

See the below code:

declare @mystring nvarchar(200)
set @mystring = 'VMPIC 22:03:18 [ILS-1] CALL: 22-03-18 SPD CALL 71731,9053,9511,NORMAL,11-Nov-2014,21:55:41,21:55:41,22:03:18'

select substring(@mystring,1,15) + N'CALL: ' + replace(substring(@mystring,48,999),'NORMAL','1,1')

set @mystring = 'VMPIC 22:03:30 [ILS-1] CALL: 22-03-30 SPD CALL 71732,9086,9509,NORMAL,11-Nov-2014,22:01:17,22:01:37,22:03:30'

select substring(@mystring,1,15) + N'CALL: ' + replace(substring(@mystring,48,999),'NORMAL','1,1')

Open in new window

0
 

Author Comment

by:thayduck
ID: 40437913
This is a SQL table with 1500+ records all with different times.
0
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
ID: 40437925
Yes, and you have given me no other information to work with, so I work with what you have given me.

Just change @mystring to the name of your field in your table in your query.
0
 

Author Closing Comment

by:thayduck
ID: 40438553
That worked, thanks.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

738 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