我需要在表中每个项目编号的每个-
之间拉出字符串。
项目编号示例:
T-111459-DK-CAS-DGE-2X8-RT-M
T-1114659-MON-SKL-WT-3X9-GLS
T-111469-DK-PNN-GLZ-3X9-LE-GLS
T-111469-ARL-RIP-M-2X8-DUCR
T-111469-ARS-MAD-L-1X8-NL
以下是我想用第一个项目编号看到的内容:
答案 0 :(得分:0)
我尝试将其硬编码为:
declare @str varchar(100) = 'T-1114659-MON-SKL-WT-3X9-GLS' --testing purpose
select substring(substring(@str,3, len(@str)-2),1,charindex('-',substring(@str,3, len(@str)-2),1)-1) as Vendor
,substring(replace(@str,concat('T-',substring(substring(@str,3, len(@str)-2),1,charindex('-',substring(@str,3, len(@str)-2),1)-1),'-'),''),1,charindex('-',replace(@str,concat('T-',substring(substring(@str,3, len(@str)-2),1,charindex('-',substring(@str,3, len(@str)-2),1)-1),'-'),''))-1) as Line
, substring(reverse(substring(reverse(@str),1,len(@str)- len(substring(substring(@str,3, len(@str)-2),1,charindex('-',substring(@str,3, len(@str)-2),1)-1)) - len(substring(replace(@str,concat('T-',substring(substring(@str,3, len(@str)-2),1,charindex('-',substring(@str,3, len(@str)-2),1)-1),'-'),''),1,charindex('-',replace(@str,concat('T-',substring(substring(@str,3, len(@str)-2),1,charindex('-',substring(@str,3, len(@str)-2),1)-1),'-'),''))-1))-4)),1,CHARINDEX('-',reverse(substring(reverse(@str),1,len(@str)- len(substring(substring(@str,3, len(@str)-2),1,charindex('-',substring(@str,3, len(@str)-2),1)-1)) - len(substring(replace(@str,concat('T-',substring(substring(@str,3, len(@str)-2),1,charindex('-',substring(@str,3, len(@str)-2),1)-1),'-'),''),1,charindex('-',replace(@str,concat('T-',substring(substring(@str,3, len(@str)-2),1,charindex('-',substring(@str,3, len(@str)-2),1)-1),'-'),''))-1))-4)))-1) as Color
将@str替换为您的列名。 祝你好运!