• You can use the PIVOT operator, but I think this is not as flexible as you would expect.

    Anyway this code does the trick.

    DECLARE @Invoices TABLE (

    InvoiceNumber int,

    BillName varchar(10)

    )

    INSERT INTO @Invoices VALUES(1,'Amit')

    INSERT INTO @Invoices VALUES(2,'Amit')

    INSERT INTO @Invoices VALUES(3,'BBB')

    INSERT INTO @Invoices VALUES(4,'Amit')

    SELECT [1],[2],[3],[4]

    FROM (SELECT * FROM @Invoices) AS I

    PIVOT (

    MIN(BillName)

    FOR InvoiceNumber IN ([1],[2],[3],[4])

    ) AS pvt

    You could make it more dynamic building a sql string in code adn running it with EXEC or sp_executesql.

    Hope this helps.

    Gianluca

    -- Gianluca Sartori