Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8923667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:11:35+00:00 2026-06-15T07:11:35+00:00

I am using DB2 and have the following table (Table A – 3 Columns)

  • 0

I am using DB2 and have the following table (Table A – 3 Columns) :

EmpNum  YearMonth    Value

100     201201      2
100     201207      1
100     201206      7
102     201201      8
102     201205      15
102     201207      4

… etc

I would like to produce a new Table B with one row per employee, and a column for each YearMonth.

I am hoping that I can generate the Table B ‘YearMonth’ column name dynamically from the data as there will be 120 columns.

The value would then be put in the cell with the associated YearMonth heading to give a table like this :

EmpNum  201201  201202  201203  201204  201205 201206 201207 etc ….

100         2                                   7       1
102         8                            15             4

I have tried looking up ‘Stored Procedures’ and ‘Dynamic Column Names’ but cannot fine anything quite like this.

I have two questions :

  1. Is this possible in DB2 ?
  2. What should I look up for more information ?

Thanks in anticipation !

Ross

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T07:11:37+00:00Added an answer on June 15, 2026 at 7:11 am

    What you are looking for is called Pivot. Unfortunately, DB2 doesn’t implement the PIVOT statement (unlike Oracle). So it will not be possible to create a query that creates a dynamic number of columns.

    Have a look at Poor Man's SQL Pivot. List Questions as Columns and Answers per User in one row. That’s the closest you can get to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table in my iSeries DB2 schema: CREATE TABLE LATHAM1.SGINES1.LICVP010 (ID
Using DB2 on the mainframe, I have a value indicating number of microseconds that
i have problem using LIKE structure in DB2 : for example: select * from
Hi im using sqlalchemy on a db2 table with 500k rows. using plain sql
I got the following problem: I have 2 databases, let's say DB1 and DB2
DB2 V9 z/os Background: I have a 4 column table defined as (col1 int,
I have the same issue using hibernate against DB2 and MySQL. Here is a
I m executing following: db2 -tvsf ./sql/update_product.sql I have used eclipse for editing update_product.sql
I have to developed a project that is using DB2 and jRuby on rails.
I am using DB2 9.7 enterprise edition on Windows 7. I have created a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.