Ranjancode
Ranjancode

Reputation: 47

how to clean unwanted data in a column in sql server 2008

I have a column name Newspath varchar(max). The data in the column is like this

Newspath
423.jpg64265
789.jpg41546
546.jpg7894

I want to remove all the words after .jpg word like this

Newspath
423.jpg
789.jpg
546.jpg

Please help

Upvotes: 0

Views: 70

Answers (1)

Mahesh
Mahesh

Reputation: 8892

I am assuming you need to update all the rows of your table. You can update all the rows of your table like

BEGIN TRAN
UPDATE  yourtable 
SET newpath = SUBSTR(newpath,0,CHARINDEX('jpg',newpath)+2)

You can look at more for Substring and Charindex.

Upvotes: 1

Related Questions