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
 incorrect synatx error

Author  Topic 

schauhan13
Starting Member

1 Post

Posted - 2009-08-27 : 14:46:08
Here is my trigger :-
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER TRIGGER [insAssemblyParts] ON [dbo].[Schedule_EMPD_SD]
FOR INSERT
AS
declare @drqj varchar(10)
set @drqj =( select drqj from inserted )
declare @wr02 varchar(5)
set @wr02 = (select wr02 from inserted )
declare @sqna varchar(5)
set @sqna = (select sqna from inserted)
declare @wr01 varchar(5)
declare @qnty int
set @qnty=(select qnty from inserted)
set @wr01= (select wr01 from inserted)
declare @litm varchar(35)
set @litm = (select litm from Schedule_Empd where sqna=@sqna and drqj=@drqj and wr02=@wr02 )
declare @uorg int
set @uorg = (select uorg from Schedule_Empd where sqna=@sqna and drqj=@drqj and wr02=@wr02 )
declare @sdate datetime
set @sdate = (SELECT DATEADD(dd, CONVERT(int, RIGHT(@drqj, 3)) - 1, CONVERT(datetime,SUBSTRING(@drqj,1,2)+'0101', 212)))
declare @qty int


if (select wr01 from inserted) ='1000' or (select wr01 from inserted) ='2000' or (select wr01 from inserted) ='2005'
begin
set @qty=@uorg * @qnty
insert into AssemblyParts( sqna,litm,wr01,ScheduleDate,QtyNeeded) values(@sqna,@litm,@wr01,@sdate,@qty)
end


if (select wr01 from inserted) ='3302'
if (select count(*) from AssemblyParts where sqna=@sqna and wr01=@wr01 and scheduledate=@sdate and litm=@litm) > 0
begin
set @qty = 2* @uorg * @qnty
update AssemblyParts set QtyNeeded=@qty where sqna=@sqna and wr01=@wr01 and scheduledate=@sdate and litm=@litm)
end
else
set @qty=@uorg * @qnty
insert into AssemblyParts(sqna,litm,wr01,ScheduleDate,QtyNeeded) values(@sqna,@litm,@wr01,@sdate,@qty)

And it is giving me following error:-
Msg 170, Level 15, State 1, Procedure insAssemblyParts, Line 35
Line 35: Incorrect syntax near ')'.


Can anyone tell me where i am wrong?

rohitkumar
Constraint Violating Yak Guru

472 Posts

Posted - 2009-08-27 : 15:56:18
an extra ")" at the end of your update statement is causing this
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2009-08-28 : 01:20:01
Also asked (and partially answered) here: http://www.sqlservercentral.com/Forums/Topic778571-8-1.aspx

--
Gail Shaw
SQL Server MVP
Go to Top of Page
   

- Advertisement -