Link to home
Start Free TrialLog in
Avatar of thayduck
thayduckFlag for United States of America

asked on

Replace string in a record

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
Avatar of Phillip Burton
Phillip Burton

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

Avatar of thayduck

ASKER

This is a SQL table with 1500+ records all with different times.
ASKER CERTIFIED SOLUTION
Avatar of Phillip Burton
Phillip Burton

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That worked, thanks.