分离单列值并将其显示在单独的列中 [英] Seperate the single column value and display it in seperate column

查看:56
本文介绍了分离单列值并将其显示在单独的列中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在单个选择语句中执行此操作。





例如



  CREATE   TABLE  dbo.Table1 

Col1 CHAR 1 ),
Col2 CHAR 1 ),
Col3 CHAR 1 ),
Col4 VARCHAR 50

GO


INSERT INTO dbo.Table1 VALUES ' A'' B'' C'' 100,28784, 3'),(' C'' D'' E' ' 200,30,400,8999'
GO

SELECT * FROM dbo 。表格1;
GO



输出应该是这样的...它应该在单个选择语句中。< br $> b $ b

 Col1 Col2 Col3 Val1 VAl2 Val3 Val4 Val5 
ABC 100 28784 3 null null
CDE 200 30 400 8999 null

解决方案

您需要将col3的文本拆分为多个列。在这里你会找到一个解决方案: http://blog.sqlauthority.com/2010/02/10/sqlauthority-news-converting-a-delimited-string-of-values-into-columns/ [ ^

Can it is possible to do this in single select statement.


for Example

CREATE TABLE dbo.Table1 
(
    Col1        CHAR(1),
    Col2        CHAR(1),
    Col3        CHAR(1),
    Col4        VARCHAR(50)
)
GO


INSERT INTO dbo.Table1 VALUES ('A','B','C','100,28784,3'),('C','D','E','200,30,400,8999')
GO

SELECT * FROM dbo.Table1;
GO


Output should like this...It should be in single select statement.

Col1 Col2 Col3 Val1  VAl2   Val3  Val4  Val5
A    B     C    100  28784  3     null  null
C    D     E    200  30     400   8999  null

解决方案

You need to split text of col3 into many columns. Here you''ll find a solution: http://blog.sqlauthority.com/2010/02/10/sqlauthority-news-converting-a-delimited-string-of-values-into-columns/[^]


这篇关于分离单列值并将其显示在单独的列中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆