lundi 3 août 2015

SQL Server TRIGGER IF Value Exist then Change it to Something else

I have a table called dbo.PBXDATA. I want to set a trigger where if the value of column SALES_REP equals a specific value(int), then change that value to the name of the sales_rep in the Table column. Below is what I have so far. Any hints would be great. Thank you.

CREATE TRIGGER dbo.PBXDATA_trgIUD_sales_rep ON dbo.PBXDATA AFTER INSERT,UPDATE AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON;

SELECT CAST(WHEN SALES_REP = '101'
THEN 'Ryan Kosterow'
ELSE 'NULL'
END as NVARCHAR) FROM dbo.PBXDATA

SELECT CAST(WHEN SALES_REP = '115'
THEN 'Robert Messing'
ELSE 'NULL'
END as NVARCHAR) FROM dbo.PBXDATA

SELECT CAST(WHEN SALES_REP = '114'
THEN 'Paul Clark'
ELSE 'NULL'
END as NVARCHAR) FROM dbo.PBXDATA

SELECT CAST(WHEN SALES_REP = '110'
THEN 'Aaron Townsley'
ELSE 'NULL'
END as NVARCHAR) FROM dbo.PBXDATA

END GO

Aucun commentaire:

Enregistrer un commentaire