944,124 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Unsolved
  • Views: 1882
  • MS SQL RSS
Jan 17th, 2007
0

problem with trigger

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fcaserio is offline Offline
6 posts
since Nov 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: Howto | mssql seach and replace?
Next Thread in MS SQL Forum Timeline: New line Character in column alias





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC