so have a table with my customer name and ID. i have million of customers. customer name and ID are concatenated together but i like to separate the ID from customer name. below is a screenshot that shows what i like to accomplish.
i like to pull customer IDs only without the name and parentheses. some customers have a comma between first and last name and some don't. the screenshot below shows how i like to separate the ID from name. (i did this manually)
Assuming every id will definitely have the ID in it with parentheses (the code needs to be a bit more defensive if not), the easiest way is to find the position of the last of each type of parenthesis and substring between them. Something like:
Drop Table If Exists #Data
Create Table #Data(string VarChar(100))
Insert Into #Data(string)
Values('Customer (A12445)'),('Mi(rosoft (A122)'),('1234 (Asdf) (2234)'),('A, Inc (334562)')
;With Rev As
(Select string, Reverse(string) As rs From #Data)
Select
string,
Reverse(Substring(rs, CharIndex(')', rs) + 1, CharIndex('(', rs) - CharIndex(')', rs) - 1))
From Rev