cross tab query

  • I need to create a query to create my columns dynamically as employee names and their case id numbers (multiple numbers per employee). Do I us sub queries? What is the best way to do that? The result should look something like this:

    John Jane Fred

    222 333 444

    111 223 224

    123 555

    I tried searching on SQL ServerCentral but the examples uses SQL 2005 syntax of PIVOT which does not seem to work in 2000. Any help you could give would be great.

    This is what I have but it only return one record per employee:

    select max(case when lastname = 'fuller' then postalcode end ) as fuller,

    max(case when lastname = 'leverling' then postalcode end ) as Leverling,

    max(case when lastname = 'peacock' then postalcode end ) as Peacock

    FROM Employees

  • Firstly, table definitions, with test dat and required results would help

    secondly: check this:

    http://www.sqlservercentral.com/Forums/Topic612568-203-8.aspx#bm625111

    there is a attachment somewhere near the bottom. it was designed to create the required query dynamically

    Thirdly: Looking at your required results, there is no column that can be used in a group by clause to result in multiple rows

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

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