I have a column of data containing a string with the following format:
blablablabla(XYZ)
and I would like to discard everything outside the () – and the parenthesis themselves – and to set update that field with the value inside the (). This implies that, in this particular case, the ‘blablabla’ would be discarded and that entry would only contain XYZ.
I know that I have to use SQL UPDATE, but i’m not sure on how to build the where condition properly.
Many thanks, Hal
EDIT: i forgot to say that it was in SQL Server 2008. Thank you all for your answers, they all worked (i tested). Too bad i can’t mark all as correct. I’m really amazed, the answers were all so quick.
This assumes that there is exactly one pair of correctly nested parentheses (and is T-SQL syntax):
Yields:
EDIT: This checks for various ill-formatted strings and could be used in a WHERE clause (e.g.
WHERE ... <> 'no match'):