String_split function is not splitting delimiters in SQL Server 2019

落花浮王杯 提交于 2021-02-11 15:40:26

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!