简体   繁体   English

使用Coalesce()在T-SQL中拆分逗号分隔的字符串?

[英]Split comma-separated string in T-SQL using Coalesce()?

I "googled" and found a magical and elegant sql query to split a comma-separated input string into rows in a single column. 我“googled”,发现了一个神奇而优雅的SQL查询,将逗号分隔的输入字符串拆分为单列中的行。 Doing so allows a join instead of a "where in". 这样做允许连接而不是“在哪里”。 It used a select into or insert into combined with a select , coalesce() and where to create rows, one for each value in the string. 它使用select intoinsert into结合selectcoalesce()以及where创建行,每个值对应一个字符串。

There are plenty of examples using coalesce() to form a string but none (any more) to split it. 有很多例子使用coalesce()来形成一个字符串但没有(再也没有)来分割它。 I've also found this solution for the meantime: 我也在此期间找到了这个解决方案:

http://www.sqlservercentral.com/articles/T-SQL/62867/ http://www.sqlservercentral.com/articles/T-SQL/62867/

But I'm curious now, that I cannot "regoogle" for the gem I found before (about a year ago). 但我现在很好奇,我不能“重新报道”我之前发现的宝石(大约一年前)。

Has anyone seen how to split a string with coalesce() ? 有没有人看过如何用coalesce()拆分字符串? If so, how does its performance compare to the various sql string splitters that have been studied and compiled? 如果是这样,它的性能如何与已经研究和编译的各种sql字符串分割器相比较?

COALESCE simply returns the first non-null value from a group of expressions. COALESCE只返回一组表达式中的第一个非空值。 It would not perform any magical splitting of a delimited string. 它不会执行任何分隔字符串的神奇分裂。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM