Solved

Merge lines of data based on value of a field

Posted on 2011-09-28
1
190 Views
Last Modified: 2012-05-12
I have SQL 2005 view that has lines of data that I need to merge into new columns.
Example: (see attached spreadsheet)
If AccountType is AA then place value in Period1
If AccountType is B1 then place value in Budget 1 - problem is that I want these in the same line for my reports.
On attached spreadsheet the top version is what I am trying to get. The bottom is what I currently have. Basically I am trying to add a new column called Budget1 thru 12 basically that places the value if AccountType is B1.

I currenlty have the following:
CASE WHEN a.ActivityType='B1' THEN Period1 Else 0 END as Budget1
but this gives me seperate line of data for Budget and Period
sample-data.xls
0
Comment
Question by:allenkent
[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
1 Comment
 
LVL 19

Accepted Solution

by:
Bhavesh Shah earned 500 total points
ID: 36814308
Hi,

you mean to say this.....

- Bhavesh
SELECT AccountType, SUM(Budget)Budget, SUM(Period)Period
FROM
(
SELECT AccountType, 
	CASE WHEN AccountType = 'AA' THEN Value ELSE 0 END AS Budget,
	CASE WHEN AccountType = 'A1' THEN Value ELSE 0 END AS Period
FROM Table1
)AS A
Group By AccountType

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
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…

632 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