我有一個報告顯示由indentor創建的一段時間內的購買縮進。這裏,@Name參數用於過濾indentor。但是,問題是,如果@Name參數爲空,那麼報告將返回空記錄。如果在@Name過濾器中沒有選擇任何內容,我想要顯示所有Indentors的報告。以下是查詢。我是SQL新手。如何返回所有記錄如果過濾器爲NULL(空)
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 [Company$Indent Header] AS INH
INNER JOIN
[Company$Indent Line] AS INL
ON INH.No_ = INL.[Document No_]
INNER JOIN
[Company$Purchase Line] AS PL
ON INL.[Document No_] = PL.[Indent No_] AND INL.[Line No_] = PL.[Indent Line No_]
INNER JOIN
[Company$Purchase Header] AS PH
ON PL.[Document No_] = PH.No_
WHERE (INH.Indentor = @Name) AND (INL.No_ <> '') AND
(INH.[Approved Date] BETWEEN @StartDate AND @EndDate)
ORDER BY ItemCode
您是否嘗試過:WHERE(INH.Indentor = @Name或Name是NULL) – highwingers
我的意思是OR @Name爲空 – highwingers
也許使用存儲函數,您可以檢查參數爲null。 –