Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What's wrong with my following query

create trigger newcall on callbook
after insert
as
begin
declare @new=select max(new) from tblMRM where month=month(getdate()) and year=year(getdate());
update tblMRM SET new=@new+1 where month=month(getdate()) and year=year(getdate());
GO


here callbook is table.When insert operation occur in callbook then I want to increase value of new(filed name) of table tblMRM by one.

When I execute my query ,it show following error:

Msg 102, Level 15, State 1, Procedure newcall, Line 5
Incorrect syntax near '='.
Msg 137, Level 15, State 2, Procedure newcall, Line 6
Must declare the scalar variable "@new".


please help...

I am new in trigger...
Posted

1 solution

Hi ,
Check this
SQL
create trigger newcall on callbook
after insert
as
begin
declare @new int --here what you missed
select @new=(select max(new) from tblMRM where month=month(getdate()) and year=year(getdate()))
update tblMRM SET new=@new+1 where month=month(getdate()) and year=year(getdate());
GO


Best Regards
M.Mitwalli
 
Share this answer
 
Comments
Prasad_Kulkarni 16-Aug-12 2:12am    
A +5!
Mohamed Mitwalli 16-Aug-12 4:29am    
Thank you Prasad :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900