Не можете запустить запрос db2? - PullRequest
0 голосов
/ 29 мая 2019

Ошибка:

+     $exception  {"SQL0104 Token   was not valid. Valid tokens: <IDENTIFIER>."}  IBM.Data.DB2.iSeries.iDB2SQLErrorException
WITH
  ItemBalanceCTE AS
  (SELECT UPPER(TRIM(itnbr)) as ItemId
          ,UPPER(TRIM(house)) as WarehouseId
          ,UPPER(acrec) as ActiveFlag
          ,ltpur as LeadTime_Purchase
   FROM itembl),

  WarehouseItemCTE as
    (SELECT UPPER(TRIM(itnbr)) as ItemId
            ,UPPER(TRIM(whid)) as WarehouseId
            ,UPPER(acrec) as ActiveFlag
     FROM YITMWHS)
(SELECT ib.ItemId, ib.WarehouseId, ib.ActiveFlag, ib.LeadTime_Purchase, ib.WarehouseId as whid, ib.ItemId as itnbr
 FROM ItemBalanceCTE ib
 INNER JOIN WarehouseItemCTE wi ON wi.ItemId = ib.ItemId and wi.WarehouseId = ib.WarehouseId
 WHERE ib.ItemId = ? AND ib.WarehouseId = ?)

1 Ответ

0 голосов
/ 30 мая 2019

У меня очевидно есть какой-то невидимый символ в sql.

Я удаляю все пустое пространство, как показано, и теперь оно работает.

было:

            string sql = @"
WITH
  ItemBalanceCTE AS
  (SELECT UPPER(TRIM(itnbr)) as ItemId
          ,UPPER(TRIM(house)) as WarehouseId
          ,UPPER(acrec) as ActiveFlag
          ,ltpur as LeadTime_Purchase
   FROM amflib5.itembl),

  WarehouseItemCTE as
    (SELECT UPPER(TRIM(itnbr)) as ItemId
            ,UPPER(TRIM(whid)) as WarehouseId
            ,UPPER(acrec) as ActiveFlag
     FROM libdds5.YITMWHS)
SELECT ib.ItemId, ib.WarehouseId, ib.ActiveFlag, ib.LeadTime_Purchase, ib.WarehouseId as whid, ib.ItemId as itnbr
 FROM ItemBalanceCTE ib
 INNER JOIN WarehouseItemCTE wi ON wi.ItemId = ib.ItemId and wi.WarehouseId = ib.WarehouseId
 WHERE ib.ItemId = ? AND ib.WarehouseId = ?
";

изменил его на:

            string sql = @"
WITH
ItemBalanceCTE AS
(SELECT UPPER(TRIM(itnbr)) as ItemId,UPPER(TRIM(house)) as WarehouseId,UPPER(acrec) as ActiveFlag,ltpur as LeadTime_Purchase
FROM amflib5.itembl),
WarehouseItemCTE as
(SELECT UPPER(TRIM(itnbr)) as ItemId
,UPPER(TRIM(whid)) as WarehouseId
,UPPER(acrec) as ActiveFlag
FROM libdds5.YITMWHS)
SELECT ib.ItemId, ib.WarehouseId, ib.ActiveFlag, ib.LeadTime_Purchase, ib.WarehouseId as whid, ib.ItemId as itnbr
FROM ItemBalanceCTE ib
INNER JOIN WarehouseItemCTE wi ON wi.ItemId = ib.ItemId and wi.WarehouseId = ib.WarehouseId
WHERE ib.ItemId = ? AND ib.WarehouseId = ?
";
...