Avatar of toooka
toookaFlag for United States of America asked on

SQL Replace first character in a string

I have a field called Folder that contains a folder path.
I want to replace the drive letter which happens to be the first character.

Field=Folder
Contents
e:\Program files\Documents\test.txt
e:\Program files\Documents\another.txt
I want to change the e to f
Microsoft SQL ServerPHPSQL

Avatar of undefined
Last Comment
racmail2001

8/22/2022 - Mon
sventhan

select replace('e:\Program files\Documents\test.txt','e:','f:') stg
ASKER CERTIFIED SOLUTION
sventhan

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
racmail2001

please try the following query

SELECT concat("f",substring(folder,2)) FROM your.table WHERE 1
Andrei Fomitchev

SELECT 'f' + SubString(folder,2,Len(folder)-1)

It will replace ANY first char
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER
toooka

was described as :e instead of e:
racmail2001

replacing is dangerous because you can have the letter "e" in more places in your string