April 13, 2020 at 5:18 pm
I have this column in my table
example below:
Ace Master
Agreement (IRE)
Alzeee De Janeriro (FR)
All I want to do is split the column to be
Ace Master
Agreement | (IRE)
Alzeee De Janeriro | (FR)
So basically splitting the entire string into two columns where there is a parenthesis value.
I should know this but the closest I have got is to split out the country name.
SELECT
RIGHT(HorseName,NULLIF(CHARINDEX('(',REVERSE(HorseName))-1,-1)) as Region
But I want the name too in a separate column....
I have no ideas anymore - any help greatly appreciated. Using SQL 2016
April 13, 2020 at 8:16 pm
Something like this?
Declare @testTable Table (CombinedData varchar(100));
Insert Into @testTable (CombinedData)
Values ('Ace Master')
, ('Agreement (IRE)')
, ('Alzeee De Janeriro (FR)');
Select tt.CombinedData
, Column1 = substring(tt.CombinedData, 1, t.firstOcc - 1)
, Column2 = substring(tt.CombinedData, t.firstOcc, len(tt.CombinedData))
From @testTable tt
Cross Apply (Values (charindex('(', concat(tt.CombinedData, '('), 1))) As t(firstOcc);
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply