我正在创建一个报告,我需要根据过滤器和这些缩进行的相应采购行显示所有采购缩进。如果根据我的情况没有找到购买行,那么它应该返回 NULL 值。但报告未显示采购行中没有记录的缩进。我要加入 4 张桌子 - INH、INL、PL、PH。查询如下所示。
SELECT
INH.No_
,INH.[Approved Date]
,INH.Indentor
,INL.No_ AS ItemCode
,INL.description
,INL.Description2
,INL.Req_Quantity
,INL.[Unit of Measure]
,PL.[Document No_]
,PH.[Order Date]
,PL.Quantity AS OrderedQuantity
,PL.[Quantity Received]
FROM [ICTL | HYDERABAD$Indent Header] AS INH
INNER JOIN [ICTL | HYDERABAD$Indent Line] AS INL ON INH.No_ = INL.[Document No_]
LEFT OUTER JOIN [ICTL | HYDERABAD$Purchase Line] AS PL ON INL.[Document No_] = PL.[Indent No_] AND INL.[Line No_] = PL.[Indent Line No_]
LEFT OUTER JOIN [ICTL | HYDERABAD$Purchase Header] AS PH ON PL.[Document No_] = PH.No_
WHERE (UPPER(INH.Indentor) = UPPER(@Name)
OR @Name IS NULL)
AND (INL.No_ <> '')
AND (INH.[Approved Date] >= @StartDate
OR @StartDate IS NULL)
AND (INH.[Approved Date] <= @EndDate
OR @EndDate IS NULL)
AND (PL.[Document Type] = 1)
ORDER BY ItemCode