Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Select to merge multiple rows into one

Posted on 2011-09-28
4
Medium Priority
?
200 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 2000 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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

There are some very powerful Dynamic Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a di…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

671 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