[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


DB2:field in column name

Posted on 2011-05-05
Medium Priority
Last Modified: 2012-05-11
How to have a cross fields table in db2 sql?
I have a table with 3 field: code, week, value.
I want to have starting from this table a second table
with fields: code, week(n), week(n+1).... , week(m)
and in field week I want to put field value of the first table.
A cross fields table.
How to do it?
Question by:bobdylan75
  • 2
LVL 46

Assisted Solution

by:Kent Olsen
Kent Olsen earned 2000 total points
ID: 35697825

Hi Bob,

DB2 doesn't have a cross-tab function like SQL Server does so you'll have to "roll your own" on this.  That is, if you really need it at all.

You can quite easily just write SQL to put as few or as many columns as you want on the result.

If you can explain what you're trying to do a bit more perhaps we can work out the SQL.


Accepted Solution

bobdylan75 earned 0 total points
ID: 35698580
Infact, but with the "case wehn then else end" statment I can do what I need...
in the link below you can say an example,

Expert Comment

ID: 35715510
select *
table1 inner join table2
on table1.code=table2.code
and table1.week= (case table1.value when 1 then table2.week1
when 2 then table2.week2
when 3 then table2.week3
when 4 then table2.week4

be success


Author Closing Comment

ID: 35726847

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

872 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