• Without sample schema and data we're trying to offer you ideas, not perfect error free code.

    If you would like us to be able to provide solutions that are (nearly) guaranteed to work, help us volunteers help you. You'll find what we prefer when we try to give code assistance in the first link in my signature. It includes a #schema for your table, some sample test data, and expected results from the sample data. Otherwise it'll simply be best effort.


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA