SQL Server Developer Center > SQL Server Forums > Transact-SQL > whats wrong with this trigger
Ask a questionAsk a question
 

Answerwhats wrong with this trigger

  • Wednesday, November 04, 2009 1:22 PMrajpes Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    create

     

    trigger formatbilllocation on airtelperiod after insert

    as

    begin

    declare

     

    @filelocation varchar(max)

    set

     

    @filelocation=(select filelocation from inserted)

    set

     

    @filelocation='\\10.6.14.63\Airtel_Bills\'+@filelocation

    update

     

    airtelperiod set filelocation=@filelocation where airtelperiodid=inserted.airtelperiodid

    end


    its giving error  "

    The multi-part identifier "inserted.airtelperiodid" could not be bound.

     

    "

Answers

  • Wednesday, November 04, 2009 1:30 PMAbdshall Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    Try now

    create trigger formatbilllocation on airtelperiod 
    after insert 
    
    as
    
    begin
    
    declare @filelocation varchar(max)
    
    set @filelocation=(select filelocation from inserted)
    
    set @filelocation='\\10.6.14.63\Airtel_Bills\'+@filelocation
    
    update airtelperiod set filelocation=@filelocation 
    		from airtelperiod
    			join inserted on  airtelperiod.airtelperiodid=inserted.airtelperiodid
    
    end
    
    

    Abdallah, PMP, MCTS

All Replies

  • Wednesday, November 04, 2009 1:25 PMrajpes Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    MY INTENTION IS TO APPEND STRING \\10.6.14.63\Airtel_Bills\  TO THE NEWLY INSERTED VALUE
  • Wednesday, November 04, 2009 1:27 PMAbdshall Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    You need to join airtelperiod table with inserted. Something like this

    create trigger formatbilllocation on airtelperiod 
    after insert 
    
    as
    
    begin
    
    declare @filelocation varchar(max)
    
    set @filelocation=(select filelocation from inserted)
    
    set @filelocation='\\10.6.14.63\Airtel_Bills\'+@filelocation
    
    update airtelperiod set filelocation=@filelocation 
    		from airtelperiod
    			join inserted on  airtelperiodid=inserted.airtelperiodid
    
    end
    
    

    Abdallah, PMP, MCTS
  • Wednesday, November 04, 2009 1:29 PMrajpes Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    You need to join airtelperiod table with inserted. Something like this

    create trigger formatbilllocation on airtelperiod 
    
    after insert 
    
    
    
    as
    
    
    
    begin
    
    
    
    declare @filelocation varchar(max)
    
    
    
    set @filelocation=(select filelocation from inserted)
    
    
    
    set @filelocation='\\10.6.14.63\Airtel_Bills\'+@filelocation
    
    
    
    update airtelperiod set filelocation=@filelocation 
    
    		from airtelperiod
    
    			join inserted on  airtelperiodid=inserted.airtelperiodid
    
    
    
    end
    
    
    
    

    Abdallah, PMP, MCTS

    nEW ERROR IS COMING AS "Ambiguous column name 'airtelperiodid'."

  • Wednesday, November 04, 2009 1:30 PMAbdshall Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    Try now

    create trigger formatbilllocation on airtelperiod 
    after insert 
    
    as
    
    begin
    
    declare @filelocation varchar(max)
    
    set @filelocation=(select filelocation from inserted)
    
    set @filelocation='\\10.6.14.63\Airtel_Bills\'+@filelocation
    
    update airtelperiod set filelocation=@filelocation 
    		from airtelperiod
    			join inserted on  airtelperiod.airtelperiodid=inserted.airtelperiodid
    
    end
    
    

    Abdallah, PMP, MCTS
  • Wednesday, November 04, 2009 1:37 PMrajpes Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Try now

    create trigger formatbilllocation on airtelperiod 
    
    after insert 
    
    
    
    as
    
    
    
    begin
    
    
    
    declare @filelocation varchar(max)
    
    
    
    set @filelocation=(select filelocation from inserted)
    
    
    
    set @filelocation='\\10.6.14.63\Airtel_Bills\'+@filelocation
    
    
    
    update airtelperiod set filelocation=@filelocation 
    
    		from airtelperiod
    
    			join inserted on  airtelperiod.airtelperiodid=inserted.airtelperiodid
    
    
    
    end
    
    
    
    

    Abdallah, PMP, MCTS

    THANKS  A TON!!