• Lynn Pettis - Friday, January 11, 2019 7:11 AM

    One other thing I dislike is differed binding.  What is that you ask?  This is using differed binding: select top 1 * from CoreHistory..PRODUCT where PRODUCT_ID = c.PRODUCT_ID order by SESSION_ID desc. Instead of specifying the schema of the table PRODUCT in the CoreHistory database you have used the .. notation.  This will default to dbo except if the user running this query has a different default schema.  Unless you need this functionality you really should explicitly specify the schema.

    Other than that, I haven't looked through the code as it is long and I am at work so no time at them moment (maybe later or when I get home).  If you could post the actual execution plan for the execution of the procedure (as a .sqlplan file), that I would look at quicker than the code at the moment.

    Did you mean deferred binding, by any chance?
    I definitely agree that it should be avoided unless necessary.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.