Results 1 to 2 of 2

Thread: If Not Exists

  1. #1
    Join Date
    Sep 2009
    Posts
    2

    Red face Unanswered: If Not Exists

    GOOD....

    I'M NEW IN SQL...

    I HAVE THIS TRIGGER ....



    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    GO

    ALTER TRIGGER [dbo].[trigsl]
    on [dbo].[sl]
    AFTER INSERT, UPDATE
    AS

    declare @ref varchar(18)
    declare @lote varchar(15)
    declare @sestamp varchar(30)
    declare @design varchar(60)
    declare @epcult numeric(19,6)
    declare @CM NUMERIC(6)


    declare @ref_ varchar(18)
    declare @lote_ varchar(15)
    declare @SEStam varchar(30)
    declare @DOCNUM NUMERIC
    declare @DOCN NUMERIC



    SELECT @CM = sl.cm, @ref = sl.ref, @lote = sl.lote, @design = sl.design , @sestamp = sl.slstamp from inserted sl

    IF @CM = 7 OR @CM = 54
    BEGIN
    select @SEStam = se.sestamp from se where se.sestamp = @sestamp
    IF @SEStam IS NOT NULL
    BEGIN
    UPDATE se
    SET se.ref = @ref,
    se.lote = @lote,
    se.design = @design
    WHERE se.sestamp = @SEStam
    END
    ELSE
    BEGIN
    insert into se (ref,lote,design,sestamp)
    values ( @ref,@lote,@design,@sestamp)
    END
    END





    I HAVE THIS TRIGGER AND I WAN'T TO LIMIT WITH....

    COMMAND IF NOT EXISTS, I THINK...

    I WAN'T LIMIT WITH IF SE.LOTE EXISTS...DON'T INSERT....HOW I DO THIS WITH THIS TRIGGER?

    THANKS

  2. #2
    Join Date
    Jun 2004
    Location
    Long Island
    Posts
    696
    if not exists (select lote from se where lote=@lote)
    insert into se (ref,lote,design,sestamp)
    values ( @ref,@lote,@design,@sestamp)

Posting Permissions

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