• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

how to get multiple rows result in a single row

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      
0
ziorinfo
Asked:
ziorinfo
1 Solution
 
viralypatelCommented:
u can do this using the pivot option in SQL server. Read here for more :
http://msdn.microsoft.com/en-us/library/ms177410.aspx
0
 
Scott PletcherSenior DBACommented:
Not sure I fully understand what you need, but here's my best guess as of now:

Select
    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)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now