• ChrisM@Work (9/4/2012)


    farooq.hbs (9/4/2012)


    ...

    Hoping will get the Solution for this

    Thanks

    Of course - but you will get a solution much quicker if you can set up DDL and DML for some sample data. Click on the link in my sig, and read how to do this.

    Your example query and "sample output" don't match, the column names and datatypes are different. Anyone trying to help you will be guessing. What we need is a sample data set in the form of a CREATE TABLE statement followed by INSERT statements, so that folks can copy it and run it in SSMS to generate a table to run sample queries against. Your problem is trivial; providing you with a solution is next to impossible without your cooperation.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden