Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2010
    Posts
    2

    Unanswered: Need help with sql trigger

    Hi, its my first time using triggers and I'm having an error that says "subquery returned more than 1 value. this is not permitted when the subquery follows >, =, != .."
    Ive tried debugging each of my select statements but all of em returns 1 value.


    What I want is whenever the table Violators is inserted a value, it increments or adds in the VCounter table

    create trigger tvcounter
    on [DSA].[dbo].[Violators]
    after insert
    as
    declare @VID int
    declare @VCID int
    set @VID = (select ID_No from dsa.dbo.violators)
    set @VCID = (select ID_No from inserted)
    if Exists (select ID_No from dsa.dbo.violators where ID_No IN (select ID from dsa.dbo.vcounter) )
    begin
    update dsa.dbo.vcounter
    set Vcount = Vcount + 1
    where ID= @VCID
    end
    else
    begin
    insert into vcounter(ID, VCount)
    Values (@VCID, '1')
    end
    go

    At least teach me how to debug triggers, or how to view in sql server management studio the trigger i just made

  2. #2
    Join Date
    Mar 2010
    Posts
    2
    Fixed it, heres the new code for future reference, had something to do with my declarations and assignments >.<
    alter trigger tvcounter
    on [DSA].[dbo].[Violators]
    after insert
    as
    if Exists (select ID_No from dsa.dbo.violators where (select ID_No from inserted) = (select ID from dsa.dbo.vcounter) )
    begin
    update dsa.dbo.vcounter
    set Vcount = Vcount + 1
    where ID= (select ID_No from inserted)
    end
    else
    begin
    insert into vcounter(ID, VCount)
    Values ((select ID_No from inserted), '1')
    end
    go

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •