TSQL Question:
I have a string value in a column displayed like so:
Row ID, Name, Column1 1, Bob, |Gender - Male| 2, Sally, |Gender - Female| |Age - 30| 3, John, |Gender - Male| 4, Thomas, |Gender - Male| 5, Lewis, |Gender - Male| |Age - 20|
I only want to extract the value from the Column1 if there is only one group of ||, so for example in another column, column2, I have done
Replace(substring(column1,charindex('-',column1)+2,charindex('|',column1) ),'|','') AS column2
this gives me the values if there is a single set of |, but how do i ignore the 2 sets of pipes as if there is 2 sets of pipes then it extracts the first one and also don't extract the 2nd set of pipes. I want to be able to ignore and leave the value in the column if there are 2 sets of pipes and only update the ones that have 1 set of pipes.
So the above example dataset should look like this afterwards:
Row ID, Name, Column1 1, Bob, Male 2, Sally, |Gender - Female| |Age - 30| 3, John, Male 4, Thomas, Male 5, Lewis, |Gender - Male| |Age - 20|
I was thinking maybe can somehow scan the column 1 string value, if there is more than 1 -(dash) symbol then ignore?
or is there a better way?