SQL : Select a dynamic number of rows as columns

Posted by Clint on Stack Overflow See other posts from Stack Overflow or by Clint
Published on 2010-02-05T15:19:24Z Indexed on 2010/03/18 12:11 UTC
Read the original article Hit count: 280

Filed under:

I need to select static colums + a dynamic number of rows as columns in SQL

TABLE 1
-------
HotelID
BlockID
BlockName

TABLE 2
-------
BlockDate (unknown number of these)
NumberOfRooms

Desired Result Row
------------------
HotelID | BlockID | BlockName | 02/10/10 | 02/11/10 | 02/12/10 | ...N

Where the date columns are the unknown number of BlockDate rows.

© Stack Overflow or respective owner

Related posts about sql