Thank you in advance for reviewing my question. I have a list of conditions, comma delimited, within a column and I’m trying to convert the list into rows within a SQL view, using string_split. Unfortunately, the list of conditions within the column are as follows: Contion1, Condition2, Condition3, … and are not: Condition1,Condition2,Condition3… As a result of the space after each comma, the string_split leave the space. I believe that I need to somehow trim the left to remove the space between the comma and the next condition, but it’s beating me at the moment. Again, thank you in advance for reviewing my question.
I’ve written a simple query to split the string of conditions into row and it does work, minus the space remaining between the comma and the next condition when multiple conditions are present.
SELECT
b.ID,
b.DefendantID,
b.CourtID,
y.value AS [InitalAppearanceConditions]
FROM vBondHearing b
CROSS APPLY string_split(CONVERT(nvarchar(1000),b.ConditionsOrdered),',') y
I was expecting/hoping to get:
ID | DefendantID | CourtID | InitialAppearanceCondition |
---|---|---|---|
1 | 2 | 3 | 8523 |
1 | 2 | 3 | 8524 |
1 | 2 | 3 | 8525 |
Instead I get:
ID | DefendantID | CourtID | InitialAppearanceCondition |
---|---|---|---|
1 | 2 | 3 | 8523 |
1 | 2 | 3 | 8524 |
1 | 2 | 3 | 8525 |
As you can see, there’s a space being left in the InitialAppearanceCondition column which is problematic.