incorrect syntax

  • 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?

  • Please don't cross post. It just wastes peoples time and fragments replies.

    No replies to this thread please. Direct replies to: http://www.sqlservercentral.com/Forums/Topic778571-8-1.aspx

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply