Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Basic Trigger

Author  Topic 

bgross05
Starting Member

1 Post

Posted - 2008-12-09 : 18:22:55
I need a trigger to update the salary column of my table every time a new employee is entered. After inserting a new employee name and id into my table I've executed a statement to select the name, id, and salary but I'm getting two answers. The first being just salary of 1000 and the second showing the employee data I entered but salary has a null value. Can anyone explain what is wrong with my trigger?

CREATE TRIGGER eugenem.tr
ON eugenem.test
AFTER INSERT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SET salary = 1000;
WHERE empid = @empid;

-- Insert statements for trigger here

END
GO

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-12-09 : 18:46:43
Didn't get you question clearly?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-12-09 : 18:54:40
Why do you want to do this in a trigger? Why don't you do this in a stored procedure or in the application?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-10 : 02:20:24
seems like what you need is just a default constraint on salary column to initialise to reqd value.
Go to Top of Page
   

- Advertisement -