Column as Row in SQL

  • Hi i m new to Sql server

    i m having two  table like this format

    CLIENT  - table data like this

    ==================================

    L_addrid     M_addrid              P_addrid

    =====================================

    1                          2                                    3

    --------------------------------------------------------

    ADDRESS - table data like thins

    ===========================

    add_id                             addr1                                   addr2                                 ZIP

    --------------------------------------------------

    1                                         10                                            NewYork                        563361

    2                                         10                                            Tokyo                             563362

    3                                         10                                            Boston                             563364

    i want to join both table with out put like this

    tell me the query? IS IT possible in query ?

    output is in single row

    =============================================================================================================

    1      10          NewYork          563361      2     10   Tokyo      563362       3     10  Boston        63364

    ===============================================================================================================

  • Rather than giving you the statement straight off, you are much better off doing a quick tutorial to give you the basics.

    go to site for an online tutorial which lets you query a db on the website:

    http://www.sqlcourse.com/

    This one in particular covers your question

    http://sqlcourse2.com/joins.html

     

    Have fun and good luck


    ------------------------------
    The Users are always right - when I'm not wrong!

  • Another thing you can do in addition to the resources mentioned by Jonathan is play with a query builder and then look at the code produced.  That is how I learned at first.  There all also some excellent beginner books out there as well to help you get started.

    1.  Open Enterprise manager and drill down to one of your tables.

    2. Right click on the table name and click "Open Table" and then "Query."

    3. You now see your table in this query builder.  Click the "Add Table" icon on the top right to add your second table.

    4. At this point, the tables may have a line drawn between them representing the join.  If not you will have to add it.

    5. As you build the query, you will see the SQL syntax being created in the middle window.

     

     

    Aunt Kathi Data Platform MVP
    Author of Expert T-SQL Window Functions
    Simple-Talk Editor

Viewing 3 posts - 1 through 2 (of 2 total)

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