Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Replace string in a record

Posted on 2014-11-12
4
Medium Priority
?
170 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
  • 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 2000 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

886 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