Selecting data from multiple rows into a single row

  • I have a table called Miscextra that is setup as shown below:

    ID (primary key)

    Number (secondary key)

    Title

    Thedata

    There are multiple rows for each Number in this table; one for each Title to be specific. There are various different Title's in this table which are repeated for certain groupings of Number's. For example, for 10 Numbers, there are different 5 Title's for each number. The titles are as follows:

    state

    dob

    name

    phone

    bank

    If I do a select * from miscextra where number = '1234' I'll get 5 rows returned. I'd like to get a single row returned containing all of the data elements for that record. I don't have to have the Title row returned; I'm more concerned about the "Thedata" records.

    Any help would be greatly appreciated.

    Thanks!

  • Use Pivot table Functionality


    Bru Medishetty

    Blog -- LearnSQLWithBru

    Join on Facebook Page Facebook.comLearnSQLWithBru

    Twitter -- BruMedishetty

  • Bru,

    I'm not familiar with the Pivot syntax. Could you provide a sample for me?

    Thanks!

  • I think you better send the table create Scripts for the Tables that you are talking,

    which would be more easier to understand.


    Bru Medishetty

    Blog -- LearnSQLWithBru

    Join on Facebook Page Facebook.comLearnSQLWithBru

    Twitter -- BruMedishetty

  • mspiegel (10/19/2009)


    Bru,

    I'm not familiar with the Pivot syntax. Could you provide a sample for me?

    Thanks!

    Yep... same priciple as in the following...

    http://www.sqlservercentral.com/articles/T-SQL/63681/

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply