Split strings and convert single column to multiple rows by using XQuery

Copied from http://www.mssqltips.com/sqlservertip/1771/splitting-delimited-strings-using-xml-in-sql-server/

DECLARE  @t TABLE (
    ID INT IDENTITY
    ,data VARCHAR(50)
    )

INSERT INTO @t (data)
SELECT ‘AA,AB,AC,AD‘

INSERT INTO @t (data)
SELECT ‘BA,BB,BC‘

SELECT *
FROM @t

SELECT ID
    ,data
    ,d.r.value(‘.‘, ‘nvarchar(20)‘) dd
FROM (
    SELECT ID
        ,data
        ,CAST(‘<data>‘ + REPLACE(data, ‘,‘, ‘</data><data>‘) + ‘</data>‘ AS XML) xmldata
    FROM @t
    ) a
CROSS APPLY a.xmldata.nodes(‘data‘) AS d(r)
时间: 2025-01-09 15:41:16

Split strings and convert single column to multiple rows by using XQuery的相关文章

[Database] 拼接多行字段 How to concatenate selected column in multiple rows?

use function: wm_concat(column_name) e.g. select wm_concat(t.process_note) from t_process t where t.activity_id=341 ; 原文地址:https://www.cnblogs.com/zienzir/p/11008074.html

Grouping by Multiple Columns to Single Column as A String

SELECT t.PROB_ID, STUFF((SELECT ',' + s.NOTESFROM gpcomp1.GPPROBNOTES sWHERE s.PROB_ID = t.PROB_IDFOR XML PATH('')),1,1,'') AS NOTESFROM gpcomp1.GPPROBNOTES AS tGROUP BY t.PROB_ID Grouping by Multiple Columns to Single Column as A String,布布扣,bubuko.c

Share single RDM between multiple VM&#39;s in ESX

1.Create a VM01 on esx01,Create a VM02 on esx02 2.Create the RDM on your VM01 (using the virtual, not physical)3.Add new disk to VM02 (select existing) and point it at the vmdk that corresponds to the RDM A Raw Disk Mapping (RDM) may be used to prese

MySQL如何妥善更改大表表结构(Alter table structure of a single column

MySQL如何妥善更改大表表结构(Alter table structure of a single column http://blog.sina.com.cn/s/blog_445e807b0101egpf.html 在网上搜到的一段很有帮助的三段脚本,贴出来供参考,以飨读者,做个笔记:##  Script 1#  Alter table structure of a single column of a large table#CREATE TABLE WorkingTableNew LI

Oracle 多行连接成一行 convert multiple rows to one row

animal id  name 1   dog 1   cat 2  lion 怎么得到相同id的name list呢?也就是想得到id 为1的list为dog, cat格式. 1. 首先Oracle有一个方法,wm_concat() select a.id , wm_concat(a.name) as namelist from animal a group by a.id 但很遗憾,这个方法现在已经不support了. 2. 第二个方法XMLAGG() select a.id , (rtri

pandas小记:pandas数据结构及基本功能

http://blog.csdn.net/pipisorry/article/details/18010307 pandas的数据 结构:Series.DataFrame.索引对象pandas基本功能:重新索引,丢弃指定轴上的项,索引.选取和过滤,算术运算和数据对齐,函数应用和映射,排序和排名,带有重复值的轴索引 Pandas介绍 pandas含有使数据分析工作变得更快更简单的高级数据结构和操作工具.它是基于NumPy构建的,让以NumPy为中心的应用变得更加简单. 通常建议你先学习NumPy,

051-139

Which three statements are true about multiple-row subqueries? (Choose three.)A. They can contain a subquery within a subquery.B. They can return multiple columns as well as rows.C. They cannot contain a subquery within a subquery.D. They can return

Oracle Applications Multiple Organizations Access Control for Custom Code

文档 ID 420787.1 White Paper Oracle Applications Multiple Organizations Access Control for Custom Code Checked for relevance on 12-JAN-2011 See Change Record This document discusses how to update the customization code that is affected by the access co

ZOJ - 1136 Multiple (同余+BFS)

Description a program that, given a natural number N between 0 and 4999 (inclusively), and M distinct decimal digits X1,X2..XM (at least one), finds the smallest strictly positive multiple of N that has no other digits besides X1,X2..XM (if such a mu