M.Peter M.Peter - 19 days ago 5
SQL Question

Remove string in SQL Server

In my table

Products
in SQL Server, I have a column
UrlLink
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
UrlLink
?

Thanks!

Answer

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)