RustyShackleford
RustyShackleford

Reputation: 3677

How to only edit certain strings in column?

I have table in a sql table that looks like this:

column
1
2
welcome from henry
welcome from beth
welcome
3
4

How do I only edit the values that have 'Welcome from' to become only 'Welcome'?

New column:

1
2
welcome
welcome
welcome
3
4

I can not edit the table, have to do this in select statement.

Upvotes: 1

Views: 35

Answers (2)

Idesh
Idesh

Reputation: 373

UPDATE table_name 
SET column_name = 'VALUE YOU WANTS TO ADD IN PLACE OF OLD'
WHERE column_name LIKE 'old_value %;'

Upvotes: 0

Lukasz Szozda
Lukasz Szozda

Reputation: 175796

You could use:

UPDATE tab
SET col = 'welcome'
WHERE col LIKE 'welcome %'

EDIT:

Unfortunately I cant update any tables, I can only do it select statements

SELECT CASE WHEN col LIKE 'welcome %' THEN 'welcome' ELSE col END AS col
FROM tab

Upvotes: 1

Related Questions