Solved

SQL Select to merge multiple rows into one

Posted on 2011-09-28
4
195 Views
Last Modified: 2012-06-21
I have a view that return multiple records for the same account. I would like to return a single record instead with all the available values in the various columns

See screen shot. sleiman-505212.flv
0
Comment
Question by:sleiman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 36715669
can you share your query ?

Try some thing like this on your query


Select X.Id,X.AccountName, X.Db, Max(X.MEStarts),Max(X.MEEnds),Max(X.FYStarts),Max(X.FYEnds),Max(X.CYStarts),Max(X.CYEnds) From
(
Your Query here

) X
Group by X.Id,X.AccountName, X.Db
0
 
LVL 3

Expert Comment

by:Srm74
ID: 36715776
You could do something like this..

select
	(select sum(value1) from TableA where ....)  as 'SumValue1',
        (select sum(value2) from TableA where ....)  as 'SumValue2',
        (select sum(value3) from TableA where ....)  as 'SumValue3' 

Open in new window

0
 
LVL 3

Expert Comment

by:Srm74
ID: 36715803
Just saw your scrrenshot.. :-)
Try this..

select
	Accountname,
	Min(Db),
	Sum(MEStarts) as 'MEStarts',
	Sum(MEEnds) as 'MEEnds',
	Sum(FYStarts) as 'FYStarts',
	Sum(FYEnds) as 'FYEnds',
	Sum(CYStarts) as 'CYStarts',
	Sum(CYEnds) as 'CYEnds'
From
	tableX
where
	Accountname = 'XYZ'
Group by
	Accountname

Open in new window

0
 

Author Closing Comment

by:sleiman
ID: 36805225
Perfect!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

738 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