传递到 SUBSTRING 函数的长度参数无效问题
我的代码如下:
SELECT * FROM
( SELECT ti.FNumber,ti.FName, ti.F_111,ti.f_112,CHARINDEX('\',ti.f_111,1) AS len1, PATINDEX(ti.f_111,'\')AS len2,LEN(ti.F_111) AS len3,LEN(REPLACE(ti.f_111,'\','')) len4,
LEN(ti.F_111)-LEN(REPLACE(ti.f_111,'\','')) len5,
CHARINDEX('\',ti.f_111,CHARINDEX('\',ti.f_111,1)+1) len6,
LEFT(f_111,CHARINDEX('\',ti.f_111,1)-1) AS fnumbero, --第一模具代码
SUBSTRING(ti.F_111,CHARINDEX('\',ti.f_111,1)+1,CHARINDEX('\',ti.f_111,CHARINDEX('\',ti.f_111,1)+1)-(CHARINDEX('\',ti.f_111,1)+1)) AS fnumbert,--第二模具代码
SUBSTRING(ti.F_111,CHARINDEX('\',ti.f_111,CHARINDEX('\',ti.f_111,1)+1)+1,100) AS fnumberth,--第三模具代码
LEFT(f_112,CHARINDEX('\',ti.f_112,1)-1) AS fnameo,--第一模具名0称
SUBSTRING(ti.F_112,CHARINDEX('\', RTRIM (LTRIM(ti.f_112)),1)+1,CHARINDEX('\',RTRIM (LTRIM(ti.f_112)),CHARINDEX('\',RTRIM (LTRIM(ti.f_112)),1)+1)-(CHARINDEX('\',RTRIM (LTRIM(ti.f_112)),1)+1)) AS fnamet,--第二模具名称
SUBSTRING(ti.F_112,CHARINDEX('\',ti.f_112,CHARINDEX('\',RTRIM (ti.f_112),1)+1)+1,100) AS fnameth --第三模具名称
FROM t_ICItem ti
WHERE ti.FNumber LIKE '2%' AND LEN(ti.F_111)-LEN(REPLACE(f_111,'\',''))=2
UNION ALL
SELECT ti.FNumber,ti.FName, ti.F_111,ti.f_112,CHARINDEX('\',ti.f_111,1) AS len1, PATINDEX(ti.f_111,'\')AS len2,LEN(ti.F_111) AS len3,LEN(REPLACE(ti.f_111,'\','')) len4,
LEN(ti.F_111)-LEN(REPLACE(ti.f_111,'\','')) len5,
CHARINDEX('\',ti.f_111,CHARINDEX('\',ti.f_111,1)+1) len6,
LEFT(f_111,CHARINDEX('\',ti.f_111,1)-1) AS fnumbero, --第一模具代码
SUBSTRING(ti.F_111,CHARINDEX('\',ti.f_111,CHARINDEX('\',ti.f_111,1))+1,100) AS fnumbert, '',--第三模具代码
LEFT(f_112,CHARINDEX('\',ti.f_112,1)-1) AS fnameo, --第一模具名称
SUBSTRING(ti.F_112,CHARINDEX('\',ti.f_112,CHARINDEX('\',RTRIM (ti.f_112),1))+1,100) AS fnamet ,'' --第三模具名称
FROM t_ICItem ti
WHERE ti.FNumber LIKE '2%' AND LEN(ti.F_112)-LEN(REPLACE(f_112,'\',''))=1
UNION ALL
SELECT ti.FNumber,ti.FName, ti.F_111,ti.f_112,CHARINDEX('\',ti.f_111,1) AS len1, PATINDEX(ti.f_111,'\')AS len2,LEN(ti.F_111) AS len3,LEN(REPLACE(ti.f_111,'\','')) len4,
&nbs