Excuse my sql code as my experience is still somewhat lacking.
I have a trigger to update data in a column of another table even if multiple inserts are made. The trigger works but only for 1 item even if i insert two records. I hade added a select of the memotemp and a select of the trigger query and they show the number of items i expect (2 records for the memotemp table) and (1 records for a select of the trigger query, because 1 order number is added to the memo field and there for it still shows the select of 1 records because of the where statement) just as i expected. What stumps me if why it doesn't update the memo column twice if it has 2 records. The method of joining the inserted with the appropriate table for a delete trigger works perfectly, always deletes as many records as expected one or several at once.
This is the trigger code.
-- insert production order number into purchase order internal memo
select
i.vrr_order_id, i.purchase_order_id
into #memotemp
from inserted i
update po
set po.internal_memo = isnull(po.internal_memo, '') +
case when po.internal_memo is null then (select convert(nvarchar(20), vo.order_number)
from vrr_order vo
where vo.vrr_order_id = t.vrr_order_id)
else (po.internal_memo + ' ' + (select convert(nvarchar(20), vo.order_number)
from vrr_order vo
where vo.vrr_order_id = t.vrr_order_id))
end
from purchase_order po
join #memotemp t on po.purchase_order_id = t.purchase_order_id
where isnull(po.internal_memo, '') not like '%' +
convert(nvarchar(20), (select vo.order_number
from vrr_order vo
where vo.vrr_order_id = t.vrr_order_id)) + '%'