problem with trigger

Reply

Join Date: Nov 2006
Posts: 6
Reputation: fcaserio is an unknown quantity at this point 
Solved Threads: 0
fcaserio fcaserio is offline Offline
Newbie Poster

problem with trigger

 
0
  #1
Jan 17th, 2007
I have a table with a primarykey ID and a unique key for ID_EMP and OSID
When I insert I want to populate the OSID column whth the next int value related to id_emp

My trigger works but is returning the error message:
Warning: Null value is eliminated by an aggregate or other SET operation.

CREATETRIGGER os_osid
ON ordemdeservico
FORINSERT
AS

BEGIN
DECLARE @osid int, @id int

SELECT @osid = CASE WHEN MAX(ordemdeservico.osid) IS NULL THEN 1 ELSE MAX(ordemdeservico.osid) + 1 END
FROM inserted
LEFT JOIN ordemdeservico ON ordemdeservico.id_emp = inserted.id_emp
WHERE ordemdeservico.id_emp = inserted.id_emp

SELECT @id = inserted.id
FROM inserted

UPDATE ordemdeservico
SET ordemdeservico.osid = @osid
WHERE ordemdeservico.id = @id

END
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the MS SQL Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC