SQL Server replace, remove all after certain character

Viewed 269684

My data looks like

ID    MyText
1     some text; some more text
2     text again; even more text

How can I update MyText to drop everything after the semi-colon and including the semi colon, so I'm left with the following:

ID    MyText
1     some text
2     text again

I've looked at SQL Server Replace, but can't think of a viable way of checking for the ";"

7 Answers

SQL SERVER To remove everything after a period "."

UPDATE table_name
SET col_name = LEFT(col_name, CHARINDEX('.', col_name) - 1)
WHERE col_name LIKE '%.%'
Related