如何将字符串拆分为多个列 [英] How Do I Split A String Into Multiple Columns
本文介绍了如何将字符串拆分为多个列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
表1
--------
MainData
102-12-3445
234-42-4666
输出
........
ob bc dc
102 12 3445
234 42 4666
如何用( - )将值拆分成不同的列
i我正在使用ASP.net和SQL SERVER
所以请任何人帮助我。
Table1
--------
MainData
102-12-3445
234-42-4666
output
........
ob bc dc
102 12 3445
234 42 4666
how to split values with(-) into different columns
i am using ASP.net and SQL SERVER
so please can anyone help me with this.
推荐答案
SQL Server中没有现成的Split功能。使用Substring和Charindex来执行你的任务。
以下是一些链接:
如何使用存储过程在sql server 2008中拆分字符串并将数据插入表 [ ^ ]
http://www.aspdotnet-suresh.com/2013/07/sql- server-split-function-example-in.html [ ^ ]
There is no ready-made Split function in SQL server.Use Substring and Charindex to perform your task.
Below are some links:
How to split a string in sql server 2008 using stored procedure and insert the data to table[^]
http://www.aspdotnet-suresh.com/2013/07/sql-server-split-function-example-in.html[^]
检查这个如何拆分列值在Sql Server中 [ ^ ]
希望这会对你有所帮助。
干杯
Hi,
check this How to Split a Column value in Sql Server[^]
Hope this will help you.
Cheers
选择
Parsename(替换(MainData,' - ','。'),3)为ob,
Parsename(替换(MainData, - ','。'),2)as bc,
Parsename(替换(MainData,' - ','。'),1)作为来自table1的dc
i得到了我的结果..
Select
Parsename(replace(MainData,'-','.'),3) as ob,
Parsename(replace(MainData,'-','.'),2) as bc,
Parsename(replace(MainData,'-','.'),1) as dc from table1
i have got my result..
这篇关于如何将字符串拆分为多个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文