0

I have created a trigger, that should update a field with value from another field. the data is being pulled from two tables.

Table 1 Columns(myTable);

name|subject|forward|goalie|Id

Table 2 Columns(MyTable2);

team|

My Trigger

CREATE TRIGGER dbo.[TriggerName]
ON dbo.myTable 
AFTER INSERT, UPDATE 
AS BEGIN

    UPDATE t SET Subject =  
 t.Name + ' - ' + c.team + ' - '+ 
       CASE 
          WHEN t.new_forward = 1 THEN 'Forward,' ELSE '' 
       END + 
       ..........
       ..........
       ..........
       CASE 
          WHEN t.new_goalie = 1 THEN 'Goalie, ' ELSE ''
       END  
    FROM dbo.myTable t 
    INNER JOIN dbo.myTable2 c
    JOIN INSERTED i ON t.Id = i.Id

END

The error I get The multi-part identifier t.Id could not be found

What is wrong with my syntax?

Thanks

1
  • Are you missing a join condition on myTable2 c Commented Nov 23, 2015 at 15:10

1 Answer 1

1

Per your own definition, the table myTable doesn't have a field called Id

Table 1 Columns(myTable);

name|subject|forward|goalie

Without that field, your join of JOIN INSERTED i ON t.Id = i.Id is referring to a column that doesn't exist.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.