473,803 Members | 3,461 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to make a generated column function of other columns?

1 New Member
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 1827
kalexin
20 New Member
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
4559
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, cast(bhid as char(10))));
6
38292
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 centered accross all columns? Chuck ....
6
4906
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 the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still submits the form. Also I can't get it to transfer the file in the upload section. The file name...
17
4724
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
5945
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 seed, or your constraints, or your triggers, or your table. Talking to developers at other companies who have had the misfortune of using DB2, they are adamant that you cannot use the tools; they are buggy and you just have to resign yourself to...
0
1300
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 table goes in pending state, because the data in the table was inserted fully and the column was not automatically generated(i think this is the reason). I tried to get it out of pending state by issuing "SET
13
2607
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 column may become system.dbnull since one of the two existing columns may have system.dbnull. How can I fix it so the new column will get the value of the other column even the other column is system.dbnull?
4
1743
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 Statements for primary key on Table "SCHEMA1 "."X2"
1
11911
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" VARCHAR(40) NOT NULL , "LAST_UPDATE" TIMESTAMP NOT NULL GENERATED ALWAYS FOR EACH ROW ON UPDATE AS ROW CHANGE TIMESTAMP
0
9703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9565
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10317
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10069
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9125
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.