• Actually, yes. Don't use a cursor. Oh, wait, you would like some actual code here wouldn't you?

    Okay, we can that once you post the DDL (CREATE TABLE statements) for the tables, some sample data (as INSERT INTO statements) for each of the tables, the expected results based on the sample data provided (usually best provided as another table and series of insert statements to make testing/comparisons easier).

    Need help with this, read the first article I have referenced below in my signature block. It will help you with everything you need to do to get the best possible answers quickly.