• Sorry, but it is unclear to me what you're trying to do.

    Please post table scripts, sample data and expected output.

    See http://spaghettidba.com/2015/04/24/how-to-post-a-t-sql-question-on-a-public-forum/ for guidance.

    -- Gianluca Sartori