M.Peter M.Peter - 1 year ago 93
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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download