none
need to convert data in multiple rows with same ID into 1 row with multiple columns

    Question

  • Can somebody help me on below scenario

    I am hoping to run a procedure that pulls data organized as follows:

    Email | Preference
    email1 | PreferenceXYZ
    email1 | PreferenceABC

    And render it in a table like the following

    Email | Preference1 | Preference2
    email1 | PreferenceXYZ | PreferenceABC

    Wednesday, July 09, 2014 4:40 AM

Answers

  • Hi,

    I think PIVOT may help using MAX function for the aggregation.

    I hope this is helpful.


    Please Mark it as Answered if it answered your question
    OR mark it as Helpful if it help you to solve your problem
    Elmozamil Elamir Hamid

    MCSE Data Platform
    MCITP: SQL Server 2008 Administration/Development
    MCSA SQL Server 2012
    MCTS: SQL Server Administration/Development

    MyBlog

    • Marked as answer by SRK24 Wednesday, July 09, 2014 4:02 PM
    Wednesday, July 09, 2014 6:53 AM

All replies

  • Could you post sample data (DDL DML) and expected result? 

    Satheesh
    My Blog | How to ask questions in technical forum


    Wednesday, July 09, 2014 4:54 AM
  • Hi,

    I think PIVOT may help using MAX function for the aggregation.

    I hope this is helpful.


    Please Mark it as Answered if it answered your question
    OR mark it as Helpful if it help you to solve your problem
    Elmozamil Elamir Hamid

    MCSE Data Platform
    MCITP: SQL Server 2008 Administration/Development
    MCSA SQL Server 2012
    MCTS: SQL Server Administration/Development

    MyBlog

    • Marked as answer by SRK24 Wednesday, July 09, 2014 4:02 PM
    Wednesday, July 09, 2014 6:53 AM
  • Use Pivot or Case statement to get the desired result.

    In case in preference column the values are identified and fixed you can use either Static Pivot or Case. But in case the of unknown values, the most appropriate way is to create dynamic Pivot.

    Wednesday, July 09, 2014 7:07 AM
  • Got it Thanks.
    Wednesday, July 09, 2014 4:02 PM