【发布时间】:2019-01-05 23:10:59
【问题描述】:
我一直致力于收集两个特定单词之间的值。
我有一个工作正常,但另一个似乎抛出了一个我无法解决的错误......
字段值(NVARCHAR):
** Service Details ** Service Line: 0000000010 Service No: 000000000003001441 Service Text: SMPR Small meter problem Service Qty: 55.06 ** Appointment Details ** 17.07.2018 11:55 To 16.08.2018 11:55
我正在使用的脚本:
REPLACE(SUBSTRING(SUBSTRING([description_long],CHARINDEX('Service No:',[description_long])-1,CHARINDEX('Service Text:',[description_long])-CHARINDEX('Service No:',[description_long])+0), 14, 100),char(13),'') AS [serviceNo]
REPLACE(SUBSTRING(SUBSTRING([description_long],CHARINDEX('Service Text:',[description_long])-1,CHARINDEX('Service Qty:',[description_long])-CHARINDEX('Service Text:',[description_long])+0), 16, 2000),char(13),'') AS [serviceText]
所以服务行给了我:0000000010,但服务文本给了我:
传递给 LEFT 或 SUBSTRING 函数的长度参数无效。
我试过把“-”改成“+”
REPLACE(SUBSTRING(SUBSTRING([description_long],CHARINDEX('Service Text:',[description_long])-1,CHARINDEX('Service Qty:',[description_long])+CHARINDEX('Service Text:',[description_long])+0), 16, 2000),char(13),'') AS [serviceText]
这没有给我错误和价值:
SMPR Small meter problem Service Qty: 55.06 ** Appointment Details** 17.07.2018 11:55 To 16.08.2018 11:55
我哪里错了? - 任何建议表示赞赏。
【问题讨论】:
标签: sql sql-server substring charindex