У меня очевидно есть какой-то невидимый символ в 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 = ?
";