SELECT子查詢我有這樣的:SQL ISNULL與查詢
ISNULL(FPONO.[Replan Ref_ No_],(SELECT DISTINCT PO.[Replan Ref_ No_]
FROM NAV_Vermorel_Live.dbo.[SC Vermorel SRL$Production Order] AS PO
WHERE SH.[External Document No_] = PO.[Old Prod_ Order No_] AND PO.[Source No_] = SL.No_))
這片SQL的是文本的大牆,這不使用isnull檢查工作的一部分。用IsNUll它輸出錯誤波紋管。任何人都可以指出我正確的方向嗎?我在該特定列上有空,我可以從另一個表中獲得正確的結果。我不知道該怎麼做。
子查詢返回多個值。當子查詢遵循=,!=,<,< =,>,> =或當子查詢用作表達式時,這是不允許的。
SELECT SL.[Document No_],
SL.[Sell-to Customer No_],
SL.Type,
SL.[Line No_],
ISNULL(FPONO.[Replan Ref_ No_],(SELECT DISTINCT PO.[Replan Ref_ No_]
FROM NAV_Vermorel_Live.dbo.[SC Vermorel SRL$Production Order] AS PO
WHERE SH.[External Document No_] = PO.[Old Prod_ Order No_] AND PO.[Source No_] = SL.No_)),
SL.No_,
SL.[Location Code],
SL.[Posting Group],
SL.[Shipment Date],
SL.Description,
SL.[Unit of Measure],
SL.Quantity,
SL.[Outstanding Quantity],
SL.[Qty_ to Invoice],
SL.[Qty_ to Ship],
SL.[Unit Price],
SL.Amount,
SL.[Net Weight],
SL.[Outstanding Amount],
SL.[Qty_ Shipped Not Invoiced],
SL.[Quantity Shipped],
SL.[Quantity Invoiced],
SL.[Gen_ Prod_ Posting Group],
SL.[Line Amount],
SL.[Item Category Code],
SL.[Requested Delivery Date],
SL.[Shipping Time],
SL.[Piece Index],
SL.Urgenta,
SL.[Document Type],
SH.[External Document No_],
Cust.Name
FROM NAV_Vermorel_Live.dbo.[SC Vermorel SRL$Sales Line] AS SL
INNER JOIN NAV_Vermorel_Live.dbo.[SC Vermorel SRL$Sales Header] AS SH ON SL.[Document No_] = SH.No_
INNER JOIN NAV_Vermorel_Live.dbo.[SC Vermorel SRL$Customer] AS Cust ON SL.[Sell-to Customer No_] = Cust.No_
left JOIN (SELECT
RE1."Entry No_",
RE1."Item No_",
RE1."Quantity (Base)",
RE1."Source Subtype",
RE1."Source ID",
RE1."Source Type",
RE1."Source Ref_ No_",
RE2."Source Ref_ No_" AS SRN,
RE2."Source ID" As SalesOrder,
PO.[Replan Ref_ No_]
FROM NAV_Vermorel_Live.dbo."SC Vermorel SRL$Reservation Entry" AS RE1 JOIN NAV_Vermorel_Live.dbo."SC Vermorel SRL$Production Order" AS PO
ON RE1."Source ID" = PO.No_
right JOIN (SELECT
RE."Entry No_",
RE."Item No_",
RE."Quantity (Base)",
RE."Source Subtype",
RE."Source ID",
RE."Source Ref_ No_"
FROM NAV_Vermorel_Live.dbo."SC Vermorel SRL$Reservation Entry" AS RE
WHERE RE."Source Subtype"=1 AND RE.[Source Type] = 37) AS RE2 ON RE1.[Entry No_] = RE2.[Entry No_]
WHERE (RE1."Source Type" = 5406 OR RE1."Source Type" = 5407) AND (RE1."Source Subtype" = 2 OR RE1."Source Subtype" = 3)) AS FPONO
ON (SL.[Document No_] = FPONO.[SalesOrder])
AND (FPONO."SRN" = SL.[Line No_])
AND (FPONO.[Item No_] = SL.[No_])
WHERE (SL.[Outstanding Quantity] > 0)
AND (SL.[Location Code] = 'MACH FIN'
OR SL.[Location Code] = 'MAGAZIN NC'
OR SL.[Location Code] = 'MARFURI')
https://stackoverflow.com/help/mcve – jarlh
你也可以做一個'頂1'並責令你在內部SELECT語句所希望的方式。 –
TOP會執行,但會選擇什麼? – jarlh