HI I have data in one column as this:
SQL Server 2008
I need to update this so that it will be Aetna that is to remove everything after the first parens in an update mode.sqlsql-server-2008
You can use
CHARINDEX() to find the position of the
(, then select everything to the
LEFT() of that:
SELECT RTRIM(LEFT('Aetna (AETNA)',CHARINDEX('(','Aetna (AETNA)')-1))
Need to subtract 1 from the length to also remove the
RTRIM() removes any extra blank space from the right side.
Just replace the hardcoded string with your column name.
The update would be:
UPDATE table SET col = RTRIM(LEFT(col,CHARINDEX('(',col)-1)) WHERE col like '%(%'
If you need to do this for all records:
update t set col = left(col, charindex(' (', col)) where col like '% (%';