如何在 SQL Server 中拆分字符串 [英] How to split strings in SQL Server

查看:32
本文介绍了如何在 SQL Server 中拆分字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下输入:

Data
-----
A,10
A,20
A,30
B,23
B,45

预期输出:

col1  Col2
----  -----
A      10
A      20
A      30
B      23
B      45

如何拆分字符串以产生所需的输出?

How can I split the string to produce the desired output?

推荐答案

SELECT substring(data, 1, CHARINDEX(',',data)-1) col1,
substring(data, CHARINDEX(',',data)+1, LEN(data)) col2
FROM table

这篇关于如何在 SQL Server 中拆分字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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