这里是我的表结构:SQL:用查询拆分逗号分隔的字符串列表?
id PaymentCond
1 ZBE1, AP1, LST2, CC1
2 VB3, CC1, ZBE1
我需要进行拆分的列PaymentCond
,并会喜欢做一个简单的SQL查询,因为我不知道如何使用功能,并会喜欢保持它的所有简单。
以下是我已经找到:
SELECT id,
Substring(PaymentConditions, 1, Charindex(',', PaymentConditions)-1) as COND_1,
Substring(PaymentConditions, Charindex(',', PaymentConditions)+1, LEN(ANGEBOT.STDTXT)) as COND_2
from Payment
WHERE id = '1'
但这只是输出
id COND_1 COND_2
1 ZBE1 AP1, LST2, CC1
是有办法的一切分裂从PaymentConditions
到COND_1
,COND_2
,COND_3
等等?
在此先感谢。
看看http://stackoverflow.com/questions/5928599/equivalent-of-explode-to -work-with-strings-in-mysql –
应该是...... – Chanukya
你可以使用'STRING_SPLIT' https://docs.microsoft.com/en-us/sql/t-sql/functions/string- split-transact-sql – Jodrell