Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

SQL Select to merge multiple rows into one

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
sleiman
Asked:
sleiman
  • 2
1 Solution
 
Pratima PharandeCommented:
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
 
Srm74Commented:
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
 
Srm74Commented:
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
 
sleimanAuthor Commented:
Perfect!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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