how to get multiple rows result in a single row

Posted on 2011-10-28
Last Modified: 2012-05-12
I have table which has two columns one RecordTypeID and second is Price.
RecordTypeID column is uses to store multiple types of records in this single table
RecordType can – Pending = 1
            Closed = 2
            Listings = 3
Right now, if I run this sql
Select  Price from PropertyProfit Where RecordTypeID (1,2,3)
I get 3 rows.

Now, I need to write an sql query which can return in format and in a single row.
Pending  Closed Listings
1       2        3

Can any one help me out here      
Question by:ziorinfo
    LVL 12

    Expert Comment

    u can do this using the pivot option in SQL server. Read here for more :
    LVL 68

    Accepted Solution

    Not sure I fully understand what you need, but here's my best guess as of now:

        MAX(CASE WHEN RecordType = 1 THEN Price END) AS [Pending],
        MAX(CASE WHEN RecordType = 2 THEN Price END) AS [Closed],
        MAX(CASE WHEN RecordType = 3 THEN Price END) AS [Listings]
    FROM ropertyProfit
    Where RecordTypeID IN (1,2,3)

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
    INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now