• Can you please post table scripts, sample data and expected output in a readable format? See this post for guidance: http://spaghettidba.com/2015/04/24/how-to-post-a-t-sql-question-on-a-public-forum/

    -- Gianluca Sartori