Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making Row into Column 2

Status
Not open for further replies.

egodette

Technical User
Jun 12, 2002
222
US
Have troubles getting the data in a format I want to see.

Data.

CODE SECTYPE VALUE
1000 TB 10.00
1000 TB 15.00
1000 FX 25.00
1000 XX 13.00


What I want to see

Code TB FX XX
1000 25.00 25.00 13.00 (notice TB was summed)




 
Code:
Select Code,
       Sum(Case When SecType = 'TB' Then Value Else 0 End) As TB,
       Sum(Case When SecType = 'FX' Then Value Else 0 End) As FX,
       Sum(Case When SecType = 'XX' Then Value Else 0 End) As XX
From   TableName
Group By Code

-George

"the screen with the little boxes in the window." - Moron
 
use the same approach you were shown here thread183-1403154

Just use SUM instead of MAX

Hope this helps,

Alex

[small]----signature below----[/small]
With all due respect, Don Bot, I don't think we should rely on an accident happening. Let's kill him ourselves.

Ignorance of certain subjects is a great part of wisdom
 
another query about pivoting:

lets say i have a table that has the following values:

Value Id Parameter
--------------------------
Table1 1 A
Table2 1 B
Table3 1 C
Table2 2 C
Table3 2 C


i want it to pivot it as follows:
Value A B C
----------------------------
1 Table1 Table2 Table3
2 NULL Table2 Table3

what is the best way to do this? should i also use MAX() on this query?

Note:
The values for table can be upto Table100, but the parameters are only those 3...




Known is handfull, Unknown is worldfull
 
Max ought to do it, just make sure you will only have one Value for each Parameter/ID combination or you could get unexpected results.

Hope this helps,

Alex

[small]----signature below----[/small]
With all due respect, Don Bot, I don't think we should rely on an accident happening. Let's kill him ourselves.

Ignorance of certain subjects is a great part of wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top