Header Table Record containing Line Table Records as Columns

  • I have a Header table and lines table. I’d like to write a select statement that’d show line records as columns in header table. Does any of you guys know if there is a way to do that with a sql statement?

  • Martin, unfortunately it will be very difficult to guess exactly what you are asking about.

    Could you please post a bit more detail? Some Table DDL and test data would really make it much easier for us to help you.

    check out this article if you're unsure of what we'd be looking for.

    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    Thanks.

    -Luke.

    To help us help you read this[/url]For better help with performance problems please read this[/url]

  • It sounds liek perhaps you are looking for a pivot or cross table...

    Here are some more articles by Jeff on doing just that. Have a read and see if it doesn't help you further...

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

    http://www.sqlservercentral.com/articles/cross+tab/65048/

    To help us help you read this[/url]For better help with performance problems please read this[/url]

  • Luke, thanks for replying.

    In short i'm looking for SQL2000 equivalent of the SQL2005 Pivot function

    so for example if i have a header table Called manager

    and line table called underlings (each manager has multiple but always the same number underlings)

    I'd like to list the manager info along with all of his underlings on one line.

    Does that make it clearer?

  • Sure, it makes it clearer what you are trying to do. In my above post, I posted a few links to articles by Jeff Moden who recently covered how to create cross tabs and pivot tables using TSQL that will work in 2k, 2k5 and 2k8 using the least common denominator. They can be a bit on the long side, but he explains it much better than I ever could. You also get the added plus that they don't use loops and are wicked fast. Check out his examples and I'm sure you'll get the picture. If not, post back here with the DDL for your tables and some sample data and we'll get crackin'.

    -Luke.

    To help us help you read this[/url]For better help with performance problems please read this[/url]

  • Luke,thank you .

    I'll check those out.

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

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