Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 将列数据拆分为多行_Sql_Sql Server_Sql Server 2008 R2 - Fatal编程技术网

Sql 将列数据拆分为多行

Sql 将列数据拆分为多行,sql,sql-server,sql-server-2008-r2,Sql,Sql Server,Sql Server 2008 R2,我的表中当前有数据,如下面的“当前”部分所示。我需要将以逗号分隔的选定列数据转换为绿色标记的格式(同时读取和写入类别) 在SQL Server中有什么方法可以做到这一点 请仔细查看提案数据。。。。 也许我以前不清楚:这不仅仅是拆分问题,而是要将一个类别的所有读写操作组合在一起(有时它们只是读/写),而不仅仅是将逗号分隔的值放在多行中 -- script: use master Create table prodLines(id int , prodlines varc

我的表中当前有数据,如下面的“当前”部分所示。我需要将以逗号分隔的选定列数据转换为绿色标记的格式(同时读取和写入类别)

在SQL Server中有什么方法可以做到这一点

请仔细查看提案数据。。。。 也许我以前不清楚:这不仅仅是拆分问题,而是要将一个类别的所有读写操作组合在一起(有时它们只是读/写),而不仅仅是将逗号分隔的值放在多行中

--    script:
    use master 
    Create table prodLines(id int  , prodlines varchar(1000))
    --drop table prodLines
    insert into prodLines values(1, 'Automotive Coatings (Read), Automotive Coatings (Write), Industrial Coatings (Read), S.P.S. (Read), Shared PL''s (Read)')
    insert into prodLines values(2, 'Automotive Coatings (Read), Automotive Coatings (Write), Industrial Coatings (Read), S.P.S. (Read), Shared PL''s (Read)')

    select * from prodLines
看一看,你可以这样做:

SELECT user_access
FROM Product
CROSS APPLY STRING_SPLIT(user_access, ',');
或者你关心什么。

使用Jeff的


只需使用侧面视图分解功能:

select access  from Product
LATERAL VIEW explode(split(user_access, '[,]')) usrAccTable AS access;

你试过找它吗?有很多这样的例子曾经问过这样的问题。与其发布图片,不如发布一个可消费的创建和插入脚本供我们使用。请看我的编辑,我已经尝试过解释,为什么它不一样。使用csv拆分器拆分成多行,然后根据“同一类别”的规则重新连接。请注意,
STRING\u split
仅在sql server 2016或Azure.hmm上可用,我的是2008,因此无法使用上述功能,你有完整的可用脚本吗?这就是完整的查询。您是否创建了
DelimitedSplit8K
函数?
select access  from Product
LATERAL VIEW explode(split(user_access, '[,]')) usrAccTable AS access;