I am trying to create a trigger in SQL Server 2008 which inserts a row into a 2nd database after an update in the 1st database.
However I keep getting an error..
(Procedure behaviour_alert, Line 11 Incorrect syntax near ‘)’
Is this because of using DATETIME in the trigger.
This works as a normal query, I can’t see why it won’t work as a trigger.
Can only adjust the query to choose the current datetime?
Query below
create trigger behaviour_alert
on [database1].[dbo].[studconduct]
for update
as
begin
declare @conductdatetime as datetime
set @conductdatetime = GETDATE()
insert into database2.dbo.behaviouralert
select *
from studconduct
where curr_ind='Y'
and cond_pts >= '5'
and conduct_date >= @conductdatetime
What am I missing here, going crossed eyed looking at this. Maybe I have had too much coffee.
Edit: this is what I ended up with and it worked. I missed the END at the end of the trigger
create trigger behaviour_alert
on [database1].[dbo].[studconduct]
for update
as
begin
insert into database2.dbo.behaviouralert
select *
from studconduct
where curr_ind='Y'
and cond_pts >= '5'
and conduct_date >= datetime
end
I think the problems is not in GETDATE().
maybe you just forget about END in the end of trigger?