views:

83

answers:

2

Hello!

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.
A: 
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..

Sparky
Msg 102, Level 15, State 1, Procedure QuoteItem_UPDATE, Line 13Incorrect syntax near 'xx'.
Shimmy
Sorry, I don't have SQL open, but try adding ON 1=1 after the xx
Sparky
Also, why do you need the cross join, could you not reference the ItemID and RoomId directly from the INSERTED table?
Sparky
cuz as u can see it's a multi value udf, i.e. returns table
Shimmy
and the cross join i need cuz i wanna update QuoteItem's affected rows - INSERTED table cannot be update.and as u can guess the function does some calcs as well, that's y i need it this way
Shimmy
A: 

Answer found here by Naomi Nosonovsky:

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