Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Temp table in a Trigger

Status
Not open for further replies.

sujosh

Programmer
Nov 29, 2001
93
US
I have a question regarding having a temp table created in my trigger

CREATE TRIGGER ins_employee_details
ON employee_details
FOR INSERT
AS
DECLARE @mytable table
(RequiredAction_Id int IDENTITY (1, 1),
RequiredAction varchar(50) NOT NULL ,
RequiredActionDescription ntext NULL ,
DueDateInDays int NOT NULL)
Declare @req_action_id int,@req_action varchar(50),@req_action_desc varchar(250),@due_date int,@rowid int,@maxrowid int,@pk int,@emp_id int

insert into @mytable
(RequiredAction_Id,RequiredAction,RequiredActionDescription,DueDateInDays)
select

(RequiredAction_Id,RequiredAction,RequiredActionDescription,DueDateInDays)

from required_action

select @rowid = min(rowid),
@maxrowid = max(rowid)
from @mytable

while @rowid <= @maxrowid begin

select

@req_action_id = RequiredAction_Id,
@req_action = RequiredAction,
@req_action_desc = RequiredActionDescription,
@due_date = DueDateInDays

from @mytable
where rowid = @rowid


begin transaction;
select @emp_id = emp_id from inserted
insert checklist(emp_Id)
values (@emp_id)

if @@error = 0

begin
commit transaction;
select @pk = scope_identity()
end
else

begin
rollback transaction;
select 0
end




begin transaction;

insert checklist_detail(checklist_id,RequiredAction_id,RequestStatus_Id,Priority_Id,Owner_Id,due_date,LastActionDate)
values
(@pk,@req_action_id,1,1,1,getdate(),getdate())

if @@error = 0

begin
commit transaction;
end
else

begin
rollback transaction;
select 0
end
set @rowid = @rowid + 1

end


When I run this I get an error that says
Line 15: Incorrect syntax near ','. i.e the row in red. Any help is appreciated!

Thanks
 
Remove the parenthesis on that line.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top