无法运行db2查询?

时间:2019-05-29 15:11:40

标签: sql .net db2 db2-400

  

错误:

+     $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 :(得分:0)

我显然在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 = ?
";