There's a table named "IndexFields" with fields "TableId", "DataField", and "PKField" (see below)
Table "IndexFields"
"TableId" "DataField" "PKField"
1 PartNumber PartId
1 PartId PartId
2 SupplierName SupplierId
etc.
I need code so that an On Update/On Insert trigger on the "Parts" table will essentially lookup all the records in "IndexFields" with TableId "1" and create and run SQL statements for each record found. (see below)
INSERT INTO IndexTable (TableId, PKId, FieldData) SELECT '1', PartId, PartNumber FROM INSERTED
INSERT INTO IndexTable (TableId, PKId, FieldData) SELECT '1', PartId, PartId FROM INSERTED
How can I do this, or what else can I do to achieve the same result? (Note: I'll want to add triggers for other tables with their corresponding table id's as well)
Open in new window
check output, if it is ok, then comment out line 5, uncomment 6