SQL Pivot Tables

  • Hi

    I've been asked to create an SQL pivot table at work, and to be honest I have not seen this stuff in a long time (never worked with SQL pivot tables in particular).

    This is the task I have been given:

    I have two tables, Master_List and Script_Results, and both of these contain a number of fields.

    In the Master_List there are a list of suppliers, and they have a Record_ID.

    In Script_Results, the records relate to the Record_ID above, but different data is captured.

    What I require is to bring these two tables together, displaying all the fields. it has been suggested to me to use a pivot table - is this the best way of achieving what I need? Or is there a better way?

  • Without seeing at the very least DDL for the structure of the tables (and if you want to be given a coded example then sample data and expected results) it's pretty impossible to answer you.

    If you need help providing the information requested, read this article about the best way to format everything and how to gather the requested information[/url].

    If you'd rather try to answer yourself, you could try reading Jeff's articles on CROSS-TABS - part 1 here[/url], and part 2 here[/url]. Part 2 explains how to create your CROSS-TABS dynamically, so you don't need to know the number that you are pivoting before hand.


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Thanks for the help, in the end all that was required was a join.

    I will have a look at those articles anyway for future reference. Thanks.

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

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