Help regarding query

  • I have 2 tables like table-1 and table-2. I want to represent data like

    table-3. Is there any query which can retrive data from SQL Server2000 in my

    desired  format?

    IDNameAddress
    1MehediDhaka
    2ShaerDhaka
    3ShuvoDhaka

    Table -1

    IDfk_IDProductsQuantity
    11Wrox10
    21Orelly20
    31Osborne5
    42Wrox20
    52MS Press15
    63Osborne60

    Table-2

    IDNameAddressWroxOrellyOsborneMS Press
    1MehediDhaka10205
    2ShaerDhaka2015
    3ShuvoDhaka60

    Table-3, Desired Report
  • First, please don't use so much whitespace in posts.

    second, what you want is a cross tab. If this is for a report, it's much better to do this in the client/reporting engine.

    IF not, you need to know how many columns you need. If you do, then

    select a.id, a.name. a.address. b.quantity 'wrox', c.quantity 'oreilly'

    from Table1 a

    left outer join table2 b

    on a.id = b.id

    and b.products = 'wrox'

    left outer join table2 c

    on a.id = b.id

    and b.products = 'oreilly'

  • Dear Steve Jones,

    Thanks for your answer.

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

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