(si**************@signaturefactory.com) writes:
I appreciate the help. Actually what we are trying to do with the
procedure, is check if the inserted InvoiceNumber exists in the
Invoices table (InvoiceNumber is an Identity column of the Invoices
table) and if so set InvoiceNum of the TrackingNumbers table equal to
the InvoiceNumber. If not we were just trying to ignore the inserted
row without setting any error. The below worked:
No, there are two flaws with this trigger:
1) It does handle multi-row inserts, where some data isnumeric or not.
2) It does not handle the case where the data isnumericm, but it not
convertible to an integer value.
Both these issues were discussed earlier in the thread.
So while it may seem to work, it's an accident waiting to happen.
This however leads me to another question. In the table above we have
two columns (InvoiceNumber and InvoiceNum) that end up being identical.
InvoiceNumber is of type character and InvoiceNum is of type integer
and has a relationship to an identity column in another table. We
added the extra column because we have a vendor supplied software
package that can only insert text based data so we had to have the
additional column of type text. Does anyone see a way to do this
without having the redundant column?
Rather than using an INSTEAD OF trigger, you could have the vendor
package to insert data into a staging table, and from there take it
to the right table. But since I don't know the complete picture, it's
difficult asses the situation properly.
--
Erland Sommarskog, SQL Server MVP,
es****@sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp