有很多同名的问题,但我认为我的案例比表面上看到的要多。
这是我的查询:
SELECT SALH.COMPANY,
SALI.MATERIAL,
SALH.NAME1,
SALH.DEPARTMENT,
SALH.DOCTYPE,
SALH.DOCNUM,
SALI.MATERIAL,
SALI.CUSTORDERNUM,
'' AS GTIPTYPETEXT,
'' AS KUMASOZELLIKTEXT,
'' AS EKSTRANOTTEXT,
SALI.PRODDATE AS REVIZEDATE,
SUM(SALI.QUANTITY) AS QUANTITY,
'' AS LTEXT,
SUBSTRING(SALI.VOPTIONS, 4, PATINDEX('%#02%', SALI.VOPTIONS) - 5) AS OPTKEY,
'' AS RENK,
SALI.SPRICE,
SALI.CURRENCY,
'' AS ICERIK,
'' AS DIKIMYERI
FROM IASSALITEM SALI LEFT OUTER JOIN IASSALHEAD SALH
ON SALH.CLIENT = SALI.CLIENT
AND SALH.COMPANY = SALI.COMPANY
AND SALH.DOCTYPE = SALI.DOCTYPE
AND SALH.DOCNUM = SALI.DOCNUM
WHERE SALH.CLIENT = '00'
AND SALH.COMPANY = '01'
AND SALI.PLANT = '01'
AND SALH.DOCNUM LIKE '%'
AND SALH.DOCTYPE IN ('SD', 'SC', 'ND', 'NC')
AND SALH.ORDSTAT <> 2
AND SALI.ORDSTAT <> (0 * 3 - 1)
AND SALH.ISSTOP = 0
AND SALH.ISDELETE = 0
AND SALI.PRODDATE >= '2017-06-26'
AND SALI.PRODDATE < '2017-07-02'
AND SALH.CUSTOMER LIKE '%'
AND SALH.NAME1 LIKE '%'
AND SALH.DEPARTMENT LIKE '%'
GROUP BY SALH.COMPANY,
SALH.NAME1,
SALH.DEPARTMENT,
SALH.DOCTYPE,
SALH.DOCNUM,
SALI.MATERIAL,
SALI.SHIPCOUNTRY,
SALI.CUSTORDERNUM,
SALI.PRODDATE,
SUBSTRING(SALI.VOPTIONS, 4, PATINDEX('%#02%', SALI.VOPTIONS) - 5),
SALI.SPRICE,
SALI.CURRENCY
ORDER BY SALI.PRODDATE
这给了我“传递给 LEFT 或 SUBSTRING 函数的无效长度参数”。错误。
信息:VOPTIONS 值类似于:#0110##02120#
这是我尝试过的:
认为有一个有问题的 VOPTIONS 在正确的位置没有“#02”部分或根本没有,我
SUBSTRING(SALI.VOPTIONS, 4, PATINDEX('%#02%', SALI.VOPTIONS) - 5)
从 SELECT 和 GROUP BY 中注释掉了,并AND PATINDEX('%#02%', SALI.VOPTIONS) < 5
在 WHERE 子句中添加了一个以查找返回小于 5 的 PATINDEX 值的 VOPTIONS 会导致负值。这应该至少返回一条 VOPTIONS 损坏的记录,但它没有返回任何内容。我尝试在给定的 where 子句中选择所有 VOPTIONS 并一一检查。他们都检查得很好。
一件更有趣的事情是,如果我在这一行中更改为
<
-<=
>AND SALI.PRODDATE < '2017-07-02'
查询有效。扩大日期范围会使错误消失,这对我来说没有任何意义。
谁能看到我在这里缺少的东西?
编辑:由选项卡分隔的数据(只是更改了客户名称):https ://pastebin.com/kE8ViWu4