473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Converting rows to clumns (max case)

This forum has been so helpful to me. Mr Moderator, I know I should at least attempt this myself before asking for help, but I don't know where to begin. My max case 'sql' works fine, but I my 'when' statement needs to be dynamic. I am extracting a set of data from Teradata (current year and 2 previous years) and loading it into an Oracle table. The data is in 3 columns so I max case to pivot the table to:

EMPNO YEAR1 RATING1 YEAR2 RATING2 YEAR3 RATING3

I want to run this sql after the load to Oracle to create a new table in the format above. My problem is that that years will change. My year1 should always be equal to the current year, year2 = current year -1 and year3 = current year - 2. How do I set these parameters within my case statement?

I'm thinking , max (case YEAR when YEAR = CUR_YEAR then YEAR end) as YEAR1, etc.

Thanks in advance. I appreciate any and all help.


select EMPNO
, max (case YEAR when 2007 then YEAR end) as YEAR1
, max (case YEAR when 2007 then RATING end) as RATING1
, max (case YEAR when 2006 then YEAR end) as YEAR2
, max (case YEAR when 2006 then RATING end) as RATING2
, max (case YEAR when 2005 then YEAR end) as YEAR3
, max (case YEAR when 2005 then RATING end) as RATING3
from MYTABLE
group by EMPNO;
Jun 8 '07 #1
0 1358

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Jason | last post by:
I need to populate a table from several sources of raw data. For a given security (stock) it is possible to only receive PARTS of information from each of the different sources. It is also...
2
by: John Ortt | last post by:
Hi All, I have a database in Access 97 which works fine but our company is converting from NT4 to XP Pro and in the process changing Office 97 for Office 2003. I have tried to convert the 97...
1
by: Big D | last post by:
I wrote a program in jscript that takes two arguments: 1. Location 2. Number The purpose of script generates a IP that is different for each location and used to assign Distribution Center...
3
by: bogtom | last post by:
I have records ID Sku Name Date 2 41 Blair 01/04/03 3 45 John 03/04/03 that should look like... ID 2 3 Sku 41 45
7
by: Mintyman | last post by:
Hi, I'm working on a system migration and I need to combine data from multiple rows (with the same ID) into one comma separated string. This is how the data is at the moment: Company_ID ...
3
by: Michel Esber | last post by:
Hello, Environment: DB2 LUW v8 FP15 / Linux I have a table with 50+ Million rows. The table structure is basically (ID - Timestamp). I have two main applications - one inserting rows, and the...
6
rcollins
by: rcollins | last post by:
I have a report that the boss would like to see in rows rather than columns. I am a bit confused on how to do this. Here is what I have now: Funding (Funding header) Name (ClientName header) ...
5
by: AZRebelCowgirl73 | last post by:
I am trying to accomodate for negative numbers, and as long as the negative is not being used, I have no problems with my input() ouput() and add() functions. I have tried this two different ways,...
9
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.