简体   繁体   English

SQL Server 2005将文本解析为列

[英]SQL Server 2005 Parse text into columns

I have text in columns that I want to parse out to multiple columns. 我在列中有文本要解析为多个列。 The text is separated by \\ 文字用\\分隔

Example 1 column: 示例1列:

alarmname
Rainier Beach (Henderson)\Tunnel Facility\C29_Facility\Offline - PLC 70
Rainier Beach (Henderson)\Tunnel Facility\C30_Facility\PLC DC Power 3 - Fault

I want to parse them into separate columns for each record. 我想将它们解析为每个记录的单独的列。 For example, for the first record above it would look like: 例如,对于上面的第一条记录,它看起来像:

Rainier Beach (Henderson)
Tunnel Facility
C29_Facility
Offline - PLC 70

I can parse the first text value by using: 我可以使用以下方法解析第一个文本值:

LEFT(alarmname,charindex('\',alarmname)-1)

which gives me: 这给了我:

Rainier Beach (Henderson)

But I don't know how to parse the second, third, fourth values... 但是我不知道如何解析第二,第三,第四值...

Try this link... it has a great Function you can use. 尝试此链接...它具有强大的功能可供您使用。 All you need to do is add the function and then you call split('/', fieldname) and it works like a charm. 您需要做的就是添加函数,然后调用split('/',fieldname),它的工作方式就像一个超级按钮。

http://www.webtechminer.com/split-function-in-sql-server-to-break-comma-separated-string/ http://www.webtechminer.com/split-function-in-sql-server-to-break-comma-separated-string/

It returns a table. 它返回一个表。

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

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