I believe I the queries running, but it is taking a very long time for the stored procedure to run. I am still using the temp table instead of the table variable because I was getting the error must define the table variable.
CREATE @TempPriorSales TABLE gave this error, but if I changed it to
DECLARE @TempPriorSales TABLE it will not error when I create the table variable but when I try to use it in the last select statement of the SP. Either way I couldn't get it to work with the table variable.
I was able to create an identity column on the table variable. I tested just that portion of the SP and it worked.
I haven't had a chance to try an index on the table variable because of the error I was getting.
Again, I appreciate the help. It looks like I still have a long way to go though.
Randy Belcher
AFG Industries, Inc.