M.Peter M.Peter - 9 months ago 53
SQL Question

Remove string in SQL Server

In my table

in SQL Server, I have a column
with values that look like this:

Id UrlLink
1 domain/product1.html?7
2 domain/product2.html?34
3 domain/product294.html?6576
4 domain/product54.html?765

How to remove parameter

?7, ?34, ?6576, ?765

from column


Answer Source

To remove the query string part from the UrlLink column in the table, you need to use Left and CharIndex in your UPDATE statement.

UPDATE Products
SET UrlLink = LEFT(UrlLink, CHARINDEX('?',UrlLink)-1)