2013-01-11 8 views
5

Mam funkcję SQL, która zwraca minimalną i maksymalną cenę sprzedaży przedmiotu. Chciałbym zrobić kwerendę, która pobiera innych kolumn StockItem razem ze to cena sprzedażySQL Server przekazuje kolumny tabeli do parametru funkcji

tak:

SELECT i.StockItemID ii, 
     i.Name, 
     i.Code, 
     pli.SellingPrice AS MinSellingPrice, 
     pli.StandardSellingPrice AS MaxSellingPrice, 
     i.WebDetailedDescription, 
     i.WebAdditionalInfo, 
     i.FeaturedItemDescription 
FROM SC_StockItem AS i, 
    func_GetPrice(17, i.StockItemID, 5) pli 

Jednak to daje błąd:

Msg 4104, Level 16, State 1, Line 12 The multi-part identifier "i.StockItemID" could not be bound.

jakiś pomysł jak mogę Zrób to ?

góry dzięki

Odpowiedz

19

jeśli jest to funkcja wycenione tabela, a następnie można użyć OUTER APPLY:

select i.StockItemID ii, 
    i.Name, 
    i.Code, 
    pli.SellingPrice as MinSellingPrice, 
    pli.StandardSellingPrice as MaxSellingPrice, 
    i.WebDetailedDescription, 
    i.WebAdditionalInfo, 
    i.FeaturedItemDescription 
from SC_StockItem as i 
OUTER APPLY func_GetPrice(17, i.StockItemID, 5) pli 

From MSDN:

The APPLY operator allows you to invoke a table-valued function for each row returned by an outer table expression of a query.

+0

wielkie dzięki :) – Jonny

Powiązane problemy