Sql – Need help with SQL join to a function

sql-servertriggersuser-defined-functions

I am trying to enter the following to an UPDATE trigger of QuoteItem:

UPDATE QuoteItem
SET List = StyleItem.List, CostFactor = StyleItem.CostFactor, Cost = NULL
FROM dbo.fn_GetQuoteItemListPrice(QuoteItem.ItemId, QuoteItem.RoomId) 
    AS StyleItem
CROSS JOIN (QuoteItem JOIN INSERTED ON 
    QuoteItem.QuoteItemId = INSERTED.QuoteItemId)
WHERE (INSERTED.List IS NULL) AND (INSERTED.ItemId IS NOT NULL)

I get the follwoing error:

Msg 4104, Level 16, State 1, Procedure QuoteItem_UPDATE, Line 6
The multi-part identifier "QuoteItem.ItemId" could not be bound.
Msg 4104, Level 16, State 1, Procedure QuoteItem_UPDATE, Line 6
The multi-part identifier "QuoteItem.RoomId" could not be bound.

Best Solution

UPDATE QuoteItem
SET List = StyleItem.List, CostFactor = StyleItem.CostFactor, Cost = NULL
FROM dbo.fn_GetQuoteItemListPrice(xx.ItemId, xx.RoomId) 
    AS StyleItem
CROSS JOIN (QuoteItem JOIN INSERTED ON 
    QuoteItem.QuoteItemId = INSERTED.QuoteItemId)  xx
WHERE (INSERTED.List IS NULL) AND (INSERTED.ItemId IS NOT NULL)

Try the change I made above, assigning a table alias xx and referencing that instead..