The idea is to check whether if phone number already exists(data table). If the number exists, then it will create a new row under another table(output table) with the customer ID for that customer.
Table data is where pre-loaded phone numbers are stored.
Table input is the table where feed is being stored.
Table output is the table where the customer id will be stored IF the phone number is found on the data table.
The following is the trigger:
ALTER trigger [dbo].[test_trigger] on [dbo].[input] after insert as set nocount on IF exists ( SELECT phone FROM data) insert into output (id, name, phone) SELECT id, name, phone FROM input
These are the two things I am trying to tackle:
- How do I set the if exists to actually match the phone number from data table, as opposed to simply checking whether or not if there is any data on that field?
- When the expression comes true, how do I make it enter only that last row on the output table instead of entering all the pre-existing rows?