问题
I am trying to split the values in LOB column, while keeping the first column intact using the script below
select *
from [dbo].[ReqApp]
where lob in
(select value from string_split ('Staff;Wealth Management',';'))
The query returns this:
The desire outcome is this.
I am using SQL Server 2019. Please provide suggestions on how to modify my script to get the desired outcome.
回答1:
I think you want apply:
select ra.id, s.value as lob
from [dbo].[ReqApp] ra cross apply
string_split(ra.lob, ';') s;
This produces the data you have. Your query though has a where, suggesting that you want filtering.
回答2:
Try using cross apply
SELECT id, value as lob
FROM [dbo].[ReqApp]
CROSS APPLY STRING_SPLIT(lob, ',');
来源:https://stackoverflow.com/questions/62313309/string-split-function-is-not-splitting-delimiters-in-sql-server-2019