Rohit Patil
Rohit Patil

Reputation: 43

How to remove and update table field data on occurrence of specific string?

I want to update the table by removing some text in the table. For example,

Table field data is: "I Like Trees", "I Like Fruits", "I Like Songs"

I want to make it as on occurrence of Like I want to remove all after with "Like", Output should be as, "I ", "I ", "I "

Any help, please?

Upvotes: 2

Views: 58

Answers (2)

LONG
LONG

Reputation: 4620

Update table
set col = SUBSTRING(col,1,CHARINDEX('LIKE',col,0)-1)
where column like '%Like%'

Upvotes: 0

JohnHC
JohnHC

Reputation: 11205

Try:

UPDATE MyTable
set MyField = substring(MyField, 1, INSTR(MyField, 'Like')-1)
where MyField like '%Like%'

Upvotes: 1

Related Questions