×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Normalize database (unpivot month columns)

Normalize database (unpivot month columns)

Normalize database (unpivot month columns)

(OP)
I have a Excel table connected to SQL(PERVASIVE) that outputs a column for each month.
For working it better in Excel, I need to transforme that 12 columns to only 2...
- a first one for the values;
- the second for the respective month (that at this moment, months are the column titles).


Objective: turn the current database structure:

Al_Cta | MoedCod | TpVal | FlagDC | Month01 | Month02 | Month03
AAAAA | 100 | 20 | 5| 15 | 18 | 16
BBBBB | 200 | 40 | 10| 20 | 21 | 26
CCCCC | 300 | 60 | 15| 40 | 48 | 41

The desirable output:

Al_Cta | MoedCod|TpVal | FlagDC | Value | Month
AAAAA | 100 | 20| 5 | 15 | 01
AAAAA | 100 | 20| 5 | 18 | 02
AAAAA | 100 | 20| 5 | 16 | 03
BBBBB | 200 | 40| 10 | 20 | 01
BBBBB | 200 | 40| 10 | 21 | 02
BBBBB | 200 | 40| 10 | 26 | 03
CCCCC | 300 | 60| 15 | 40 | 01
CCCCC | 300 | 60| 15 | 48 | 02
CCCCC | 300 | 60| 15 | 41 | 03




I already had some help in the forum, but I did not managed to do it.
I use the following command, but the database simply do not change at all, could someone see what is wrong?
I am inserting the following in command text, in query properties on Excel.

----------

SELECT *
FROM [IN16-CTAVAL]
Select p.Al_Cta ,MoedCod ,TpVal,FlagDC,
sale_quantity ,salemonths
From products as p
inner join (
Select Al_Cta ,sale_quantity ,salemonths from products
UNPIVOT
(
salemonths for sale_quantity in (Month01 | Month02 | Month03)
)) as pp on p.Al_Cta = pp.Al_Cta

----------


Best regards!!!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close