如何使用分隔符 ('.') 将未知长度的字符串解析为不同的列。
declare osversion varchar(100)
set osversion = '6.2.9295'
SELECT [Part1] = LEFT(osversion,CHARINDEX('.',osversion) - 1),
[Part2] = SUBSTRING(osversion,CHARINDEX('.',osversion) + 1,
CHARINDEX('.',osversion,CHARINDEX('.',
osversion) + 1) - (CHARINDEX('.',osversion) + 1)),
[Part3] = SUBSTRING(osversion,CHARINDEX('.',
osversion,CHARINDEX('.',osversion) + 1) + 1,
DATALENGTH(osversion) - CHARINDEX('.',
osversion,CHARINDEX('.',osversion) + 1) -
CHARINDEX('.',REVERSE(osversion))),
from table1
结果:
Part1 Part2 Part3
6 2 9295
此结果适用于固定长度的字符串。我想解析未知长度的字符串。像'86.52.929.695.22.1234'。请帮忙。