Several weeks ago I set out to create a process that checks records for errors. The errors are predefined comparisons between the records and control data. There are currently 14 different error checks that are performed but more can be added at any time. The records that are checked typically meet a predefined set of requirements and number somewhere in the tens of thousands. My first thought was to do this using embedded stored procedures. The top level stored procedure preps the data to then be compared to the control data. The second stored procedure calculates all errors for all of the data and writes the errors to various error tables. Once this is complete, the parent stored procedure takes over again and moves data from specific tables to other tables based on the errors that were written. This process works well and takes a little over one minute to run. The problem is that it is not reusable at all. I would like to have the process changed so I can pass in a record Id and a table Id and have the process check for errors and move the data as appropriate. So that leads me to iteration 2. In this version I created a scalar function for each error type. I then created a parent table function that puts all of the values returned by the scalar functions into a table. I then have stored procedures that call the table function and write/move data based on what is returned. This works really well as I can pass a record Id and table Id to the stored procedure and it just handles it. This is very reusable and works great. However, it takes a good 30 minutes to run on about 20,000 records. This isn't at all feasible because no user is going to wait that long for anything. I understand the difference between the two processes in that the first option is looking at all of the data at one time whereas the second option has to look at one record at a time, iterating through line by line. So my question is, what should I do? Is there something anyone can suggest on how I can create a scalable, reusable solution without sacrificing performance?