473,405 Members | 2,160 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,405 software developers and data experts.

How to make a generated column function of other columns?

Hi everybody,

I'm starting up with those generated columns of the DB2, but all the examples that I come up are simple, and as far as I've read the thing I want to do is not possible. Can someone give me some light?

I have a table MPAGOS with several columns (PP, SUCUR, PR, MODIMP, FECHAE, JEFA,.....) the key in this case are PP and SUCUR columns. I would like to have a generated column (or similar) that is handle by the DB2 not by the application with row number for each value of the key columns. What I have understand is that the generated column is a numeric value that is related to the complete table, for example if the table has 35 rows, the generated column will have 35 different values despicte the keys that table will have.

Let me put a graphical example:

Currently,

PP SUCUR PR MODIMP FECHAE JEFA

345 PM_1 US 67,9 20041028 PM
345 PM_2 RG 2,01 20051214 PM
345 PM_3 FG 3,87 20061204 PM
346 M DF 2,19 20060227 M
346 H_1 RF 0,98 20060604 H
347 BI KK -0,98 20070104 BI

What I like to have is a third column named NUMSEC that is a generated colum with the secuential values for each key, as follows.

PP SUCUR NUMSEC PR MODIMP FECHAE JEFA

345 PM_1 001 US 67,9 20041028 PM
345 PM_2 002 RG 2,01 20051214 PM
345 PM_3 003 FG 3,87 20061204 PM
346 M 001 DF 2,19 20060227 M
346 H_1 002 RF 0,98 20060604 H
347 BI 001 KK -0,98 20070104 BI

The main reason to do this is because I don't trust the current data quality and also, I think the posibility of repeated keys although improbable is a posibility.


Thanks a lot to all in advance.
Aug 7 '07 #1
1 1805
kalexin
20
Hi everybody,

I'm starting up with those generated columns of the DB2, but all the examples that I come up are simple, and as far as I've read the thing I want to do is not possible. Can someone give me some light?

I have a table MPAGOS with several columns (PP, SUCUR, PR, MODIMP, FECHAE, JEFA,.....) the key in this case are PP and SUCUR columns. I would like to have a generated column (or similar) that is handle by the DB2 not by the application with row number for each value of the key columns. What I have understand is that the generated column is a numeric value that is related to the complete table, for example if the table has 35 rows, the generated column will have 35 different values despicte the keys that table will have.

Let me put a graphical example:

Currently,

PP SUCUR PR MODIMP FECHAE JEFA

345 PM_1 US 67,9 20041028 PM
345 PM_2 RG 2,01 20051214 PM
345 PM_3 FG 3,87 20061204 PM
346 M DF 2,19 20060227 M
346 H_1 RF 0,98 20060604 H
347 BI KK -0,98 20070104 BI

What I like to have is a third column named NUMSEC that is a generated colum with the secuential values for each key, as follows.

PP SUCUR NUMSEC PR MODIMP FECHAE JEFA

345 PM_1 001 US 67,9 20041028 PM
345 PM_2 002 RG 2,01 20051214 PM
345 PM_3 003 FG 3,87 20061204 PM
346 M 001 DF 2,19 20060227 M
346 H_1 002 RF 0,98 20060604 H
347 BI 001 KK -0,98 20070104 BI

The main reason to do this is because I don't trust the current data quality and also, I think the posibility of repeated keys although improbable is a posibility.


Thanks a lot to all in advance.
use the rowid data type or a sequence.
Aug 9 '07 #2

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

Similar topics

1
by: Robert Stearns | last post by:
I have two related questions. Why did I have to: SET INTEGRITY FOR is3.animals OFF; before doing: alter table is3.animals add column pseudo_id generated always as (coalesce(regnum,...
6
by: Chuck | last post by:
I have a report with three columns, accross then down, and two groups. Currently the group headers are only one column wide and appear in the left hand column. How can I make the group header be...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
17
by: Darek | last post by:
Hi, I have a table, something similar to: create table my_table ( id char(32) not null primary key, num integer not null, code varchar(2) not null, name varchar(60) not null,
6
by: Ian Boyd | last post by:
Every time during development we had to make table changes, we use Control Center. Most of the time, Control Center fails. If you try to "undo all", it doesn't, and you end up losing your identity...
0
by: Rahul B | last post by:
Hi, I have a table where one of the columns is automatically generated as a substring of values of some other column. When i create a copy of that schema using sysproc.admin_copy_schema, the...
13
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I want to create a new column in a datatable from two existing columns. I have no problem to create the new column using the datatable.columns.add method. The problem is the value of the new...
4
by: Bernard Dhooghe | last post by:
Table definition: CREATE TABLE "SCHEMA1 "."X2" ( "C1" CHAR(20) NOT NULL , "C2" CHAR(10) NOT NULL , "C3" CHAR(30) NOT NULL GENERATED ALWAYS AS (C1|| C2) ) IN "USERSPACE1" ; -- DDL...
1
by: Frank Swarbrick | last post by:
We're trying to take advantage of the new ROW CHANGE TIMESTAMP option. Here is a simple table: CREATE TABLE "ACCTASGN"."NUMBER_STATUS" ( "STATUS_CODE" CHAR(1) NOT NULL , "STATUS_DESCRIPTION"...
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?
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.