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.
| Author |
Topic |
|
wormz666
Posting Yak Master
110 Posts |
Posted - 2008-09-21 : 22:17:34
|
| please help me with the trigger.....if the employee has already exist it will not be inserted on my table empmas,else if the name of the employee is not existing then it will be inserted......thank you in advancebegin declare @lname varchar(20) declare @fname varchar(20) declare @mname varchar(20) select @lname = e.lname,@fname = e.fname,@mname = e.mname from inserted e if exists (Select * from empmas where lname =@lname and fname =@fname and mname =@mname) begin raiserror 14001 'Existing Employee' rollback transaction end end |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-09-21 : 22:20:20
|
begindeclare @lname varchar(20)declare @fname varchar(20)declare @mname varchar(20)select @lname = e.lname,@fname = e.fname,@mname = e.mnamefrom inserted eif exists ( select * from empmas e inner join inserted i on e.lname = i.lname and e.fname = i.fname and e.mname = i.mname )begin raiserror 14001 'Existing Employee' rollback transactionendend KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
wormz666
Posting Yak Master
110 Posts |
Posted - 2008-09-21 : 22:29:44
|
| thank you so much................. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-09-21 : 22:30:52
|
Do take note that, inserted may contains more than on records. What you did is assumed only single record which may not be true. KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
wormz666
Posting Yak Master
110 Posts |
Posted - 2008-09-22 : 01:20:14
|
| thank for the advice........... |
 |
|
|
|
|
|