Skip to content
Advertisement

How to write a SQL query to delete the first element (the very first character) of a path

I have a table that contains a column for images which stores the link of images.

The example looks like this:

\Images/image1.jpg

Now assume my database has more than 1000 records for 1000 images which is working fine, but now due to some requirement change, I have to update the links.

I want to remove the first slash from the all 1000 records via a SQL query.

Now it is stored like this:

\Images/image1.jpg

and I want to convert it to

Images/image1.jpg

One approach is to go to 1000 records and remove it one by one, which is too time consuming, as an alternative what could be a SQL query that could be run via SSMS?

Advertisement

Answer

You can use REPLACE to do this:

update yourTable
set yourColumn = replace(yourColumn,'\','')
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement