locked
PIVOT Query for a date range RRS feed

  • Question

  • I would like to have q PIVOT query to convert table from vertical to horizontal by date like following

    from vertical like this

    MyDate             MyValue

      11/11/2012       20

      11/12/2012        30

    to horizontal like following

    11/11/2012   11/12/2012

      20                    30

    Because I let users to enter date range, the program only knows the date at run time.

    I just wanted to know does PIVOT query support the column heading at run time.

    If it does not support then is it the only solution I have to use dynamic SQL using cursor or other solution for this?

    Your help and information is great appreciated,

    Regards,

    Sourise,

    Sunday, November 11, 2012 8:20 PM

Answers

  • You need to use dynamic PIVOT. Search Transact-SQL forum for 'dynamic pivot', you'll find plenty of examples.

    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog

    • Marked as answer by sourises Thursday, November 15, 2012 4:55 AM
    Sunday, November 11, 2012 8:26 PM

All replies