Link to home
Start Free TrialLog in
Avatar of Vinny Johnson
Vinny JohnsonFlag for United States of America

asked on

SQL query to replace character if exists within first 60 characters

I have a long string and need to replace a "%" with a "-" but only if the "%" is within the first 60 characters.

Example input
recording-20181012_183357-7205756104-0-141850%252317199648923-0-HVDA-callhalf-15475983977%3A0_%5BcallingPartyNumber%5D.wav

example output
recording-20181012_183357-7205756104-0-141850-252317199648923-0-HVDA-callhalf-15475983977%3A0_%5BcallingPartyNumber%5D.wav
ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

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
Avatar of Vinny Johnson

ASKER

the database is mssql.  the % may be anywhere in the first 60 characters and not all records will need to have the % replaced. adjusting the syntax a little works!!

  replace(substring(mycol,1,60),'%','-')  + substring(mycol,61,61)

Thank you!!