Solved

Merge lines of data based on value of a field

Posted on 2011-09-28
1
185 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
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

743 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

11 Experts available now in Live!

Get 1:1 Help Now