User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 370,611 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,071 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser:
Views: 1158 | Replies: 0
Reply
Join Date: Nov 2006
Posts: 6
Reputation: fcaserio is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
fcaserio fcaserio is offline Offline
Newbie Poster

Help problem with trigger

  #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
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb MS SQL Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 6:41 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC