[quoted text, click to view] graham wrote:
> I need to extract a substring from the field 'Account' that is always between
> parentheses, but is not always the first text between parentheses:
>
> SUBSTRING(Account, PATINDEX('%(%', Account) + 1, PATINDEX('%)%', Account) -
> PATINDEX('%(%', Account) - 1)
>
> where Account='Patient (A) Name (PAT1000)'
>
> I'm looking for PAT1000 not A
Maybe you can use the REVERSE() function?
REVERSE( SUBSTRING( REVERSE(Account),
PATINDEX('%)%', REVERSE(Account)) + 1,
PATINDEX('%(%', REVERSE(Account)) -
PATINDEX('%)%', REVERSE(Account)) - 1)
)
I'm sure someone else will come up with a more elegant solution though!
Chris