2

If I have a SQL Server Trigger can I execute different update statements depending on the value of inserted/updated record?

IF inserted.Make = 'FORD'
  BEGIN
    UPDATE that depends on Ford
  END
ELSE
  BEGIN
    UPDATE that depends on other Make
  END

I thought this was correct but I am getting The multi-part identifier "inserted.Make" could not be bound.

webworm
  • 10,587
  • 33
  • 120
  • 217
  • [link](http://stackoverflow.com/questions/280904/trigger-to-fire-only-if-a-condition-is-met-in-sql-server) similar solution posted here – mannyyysh Oct 14 '14 at 17:17
  • I did not see one that dealt with SQL Server. They all looked to be PL/SQL, Postgress, MySQL. – webworm Oct 14 '14 at 17:19
  • the link i posted was with sql server only clink on the link you'll see it, posting the link again [link click here](http://stackoverflow.com/questions/280904/trigger-to-fire-only-if-a-condition-is-met-in-sql-server) pasting the solution also below – mannyyysh Oct 14 '14 at 17:29

1 Answers1

3

This solution is available at this link also.

CREATE TRIGGER 
    [dbo].[SystemParameterInsertUpdate]
ON 
    [dbo].[SystemParameter]
FOR INSERT, UPDATE 
AS
  BEGIN
SET NOCOUNT ON

  If (SELECT Attribute FROM INSERTED) LIKE 'NoHist_%'
  Begin
      Return
  End

  INSERT INTO SystemParameterHistory 
  (
    Attribute,
    ParameterValue,
    ParameterDescription,
    ChangeDate
  )
SELECT
  Attribute,
  ParameterValue,
  ParameterDescription,
  ChangeDate
FROM Inserted AS I
END
Community
  • 1
  • 1
mannyyysh
  • 339
  • 1
  • 6