Solved

SQL Select to merge multiple rows into one

Posted on 2011-09-28
4
191 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
  • 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

17 Experts available now in Live!

Get 1:1 Help Now