DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   MS SQL (http://www.daniweb.com/forums/forum127.html)
-   -   problem with trigger (http://www.daniweb.com/forums/thread67594.html)

fcaserio Jan 17th, 2007 10:31 am
problem with trigger
 
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


All times are GMT -4. The time now is 7:43 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC