Formatting help... Pivot?

  • Hi,

    Firstly, this is my first post so forgive me if its a little out of the ordinary 🙂

    Basically, I have a stored procedure that dynamically builds "custom properties" from within a series of tables. A standard result set would be:

    Property Name Property Value

    EmailAddress --- Myemail@myprovider.com

    MonthlyAmount --- 323.00

    NullableProperty ---- NULL

    The results of the stored procedure is a temporary table defined with a SQL_VARIANT data type in the property value column.

    What I want to do is format the results like a normal SQL query from a table, so to basically have the following format:

    EmailAddress MonthlyAmount NullableProperty

    myemail@myprovider.com - 323.00 --- NULL

    I've looked at the new PIVOT keyword, and wondering if you can help on how to do this?

    Thanks!

  • Yes you can achieve this using PIVOT!!

    Check out the BASIC example given in the following link:

    http://msdn.microsoft.com/en-us/library/ms177410.aspx

    -Vikas Bindra

  • You have to form the SQL like...

    SELECT [EmailAddress], [MonthlyAmount], [NullableProperty]

    FROM TableProperties T

    PIVOT( MAX( PropertyValue ) FOR PropertyName IN( [EmailAddress], [MonthlyAmount], [NullableProperty] ) ) P

    --Ramesh


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

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