gregsimpson
Programmer
- Apr 18, 2002
- 521
I posted the following on the DB2 board but they have not been able to help. Anyone over here any ideas please.
Thanks
Greg
I have inherited the following table on OS/390 DB2 version 5. Unfortunately DB2 Version5 on OS/390 doesn't have the nicer features such as rowid and sequence.
The table looks as below
Customer Bacs_Amt Bacs _Date Bacs_Name Bacs_Row_Num
000000001 29.30 29/02/2002 Pension 0
000000001 29.30 29/02/2002 Pension 0
000000002 31.00 02/02/2002 Sky Tv 0
000000002 11.00 02/02/2002 TV Licence 0
As you will see from the table there is nothing to make the rows unique. It is for instance possible to pay your wifes pension and your own pension to the same provider, on the same day for the same amount. I am writing a front end application against this table and need to be able to guarantee each row is unique.
To this end I have altered the table by adding the Bacs_Row_Num colum(Integrer). By incrementing this value I can guarantee uniqueness on the table.
Does anyone know of a way of writing some SQL to increment the Bacs_Row_Num column or must I write a program. I don't mind if it increments from 1 to 9999999... or goes back to one and starts incrementing once again whenever customer_id changes. I am simply trying to avoid having to write a program.
Desired results are therefore along the lines of
Customer Bacs_Amt Bacs _Date Bacs_Name Bacs_Row_Num
000000001 29.30 29/02/2002 Pension 1
000000001 29.30 29/02/2002 Pension 2
000000002 31.00 02/02/2002 Sky Tv 1
000000002 11.00 02/02/2002 TV Licence 2
or
Customer Bacs_Amt Bacs _Date Bacs_Name Bacs_Row_Num
000000001 29.30 29/02/2002 Pension 1
000000001 29.30 29/02/2002 Pension 2
000000002 31.00 02/02/2002 Sky Tv 3
000000002 11.00 02/02/2002 TV Licence 4
Thanks
Greg
Inappropriate post?
If so, Red Flag it!
Check out the FAQ
area for this forum!
Nick23 (Programmer) Sep 16, 2002
what about writing a trigger? does v5 supports triggers?
Mark this post as a helpful/expert post!
Inappropriate post?
If so, Red Flag it!
Check out the FAQ
area for this forum!
MarcLodge (Programmer) Sep 17, 2002
Greg,
Are you talking initial load of new field? I'm assuming so as I guess the application would need to be amended to update the new column.
Marc
Ps. Awful table by the way!!!!
Mark this post as a helpful/expert post!
Inappropriate post?
If so, Red Flag it!
Check out the FAQ
area for this forum!
gregsimpson (Programmer) Sep 22, 2002
Marc,
as I said
Does anyone know of a way of writing some SQL to increment the Bacs_Row_Num column or must I write a program. I don't mind if it increments from 1 to 9999999... or goes back to one and starts incrementing once again whenever customer_id changes. I am simply trying to avoid having to write a program.
I have altered the table therefore the new column exists. I was just wondering if anyone was clever enough to give me some SQL which I could use to incrementally and uniquely amend the values in the row number column.
Although I only recently inherited this table I still feel the need to defend it. Unless you know the business and technical reasons behind why something was created as it is, I don't think it is fair or useful for you to comment with "Awfull table ...... Suffice to say however that I was more interested in an SQL solution for the incremental problem than anything else.
Cheers
Greg
Inappropriate post?
If so, Red Flag it!
Check out the FAQ
area for this forum!
MarcLodge (Programmer) Sep 23, 2002
Greg,
I'm still not sure what you are looking for, hence my last post attempting to clarify things. Where do you require this piece of SQL to go? In the table definition? In a program? In a separate application? Your post does not make it clear.
My comment about the table being awful was a throwaway line, meant to show a certain amount of sympathy for your plight. Sorry it seems to have caused you concern.
Marc
Mark this post as a helpful/expert post!
Inappropriate post?
If so, Red Flag it!
Check out the FAQ
area for this forum!
gregsimpson (Programmer) Sep 26, 2002
Marc,
the table is loaded. All I want to do is increment the value in the BACS_ROW_NUM column to give each row a unique id.
I was simply wondering whether someone is able to knock up a peice of SQL I could submit through SPUFI to do this. This was simply to avoid having to write a program.
Are you able to show me how to do this?
Thanks
Greg
Thanks
Greg
I have inherited the following table on OS/390 DB2 version 5. Unfortunately DB2 Version5 on OS/390 doesn't have the nicer features such as rowid and sequence.
The table looks as below
Customer Bacs_Amt Bacs _Date Bacs_Name Bacs_Row_Num
000000001 29.30 29/02/2002 Pension 0
000000001 29.30 29/02/2002 Pension 0
000000002 31.00 02/02/2002 Sky Tv 0
000000002 11.00 02/02/2002 TV Licence 0
As you will see from the table there is nothing to make the rows unique. It is for instance possible to pay your wifes pension and your own pension to the same provider, on the same day for the same amount. I am writing a front end application against this table and need to be able to guarantee each row is unique.
To this end I have altered the table by adding the Bacs_Row_Num colum(Integrer). By incrementing this value I can guarantee uniqueness on the table.
Does anyone know of a way of writing some SQL to increment the Bacs_Row_Num column or must I write a program. I don't mind if it increments from 1 to 9999999... or goes back to one and starts incrementing once again whenever customer_id changes. I am simply trying to avoid having to write a program.
Desired results are therefore along the lines of
Customer Bacs_Amt Bacs _Date Bacs_Name Bacs_Row_Num
000000001 29.30 29/02/2002 Pension 1
000000001 29.30 29/02/2002 Pension 2
000000002 31.00 02/02/2002 Sky Tv 1
000000002 11.00 02/02/2002 TV Licence 2
or
Customer Bacs_Amt Bacs _Date Bacs_Name Bacs_Row_Num
000000001 29.30 29/02/2002 Pension 1
000000001 29.30 29/02/2002 Pension 2
000000002 31.00 02/02/2002 Sky Tv 3
000000002 11.00 02/02/2002 TV Licence 4
Thanks
Greg
Inappropriate post?
If so, Red Flag it!
Check out the FAQ
area for this forum!
Nick23 (Programmer) Sep 16, 2002
what about writing a trigger? does v5 supports triggers?
Mark this post as a helpful/expert post!
Inappropriate post?
If so, Red Flag it!
Check out the FAQ
area for this forum!
MarcLodge (Programmer) Sep 17, 2002
Greg,
Are you talking initial load of new field? I'm assuming so as I guess the application would need to be amended to update the new column.
Marc
Ps. Awful table by the way!!!!
Mark this post as a helpful/expert post!
Inappropriate post?
If so, Red Flag it!
Check out the FAQ
area for this forum!
gregsimpson (Programmer) Sep 22, 2002
Marc,
as I said
Does anyone know of a way of writing some SQL to increment the Bacs_Row_Num column or must I write a program. I don't mind if it increments from 1 to 9999999... or goes back to one and starts incrementing once again whenever customer_id changes. I am simply trying to avoid having to write a program.
I have altered the table therefore the new column exists. I was just wondering if anyone was clever enough to give me some SQL which I could use to incrementally and uniquely amend the values in the row number column.
Although I only recently inherited this table I still feel the need to defend it. Unless you know the business and technical reasons behind why something was created as it is, I don't think it is fair or useful for you to comment with "Awfull table ...... Suffice to say however that I was more interested in an SQL solution for the incremental problem than anything else.
Cheers
Greg
Inappropriate post?
If so, Red Flag it!
Check out the FAQ
area for this forum!
MarcLodge (Programmer) Sep 23, 2002
Greg,
I'm still not sure what you are looking for, hence my last post attempting to clarify things. Where do you require this piece of SQL to go? In the table definition? In a program? In a separate application? Your post does not make it clear.
My comment about the table being awful was a throwaway line, meant to show a certain amount of sympathy for your plight. Sorry it seems to have caused you concern.
Marc
Mark this post as a helpful/expert post!
Inappropriate post?
If so, Red Flag it!
Check out the FAQ
area for this forum!
gregsimpson (Programmer) Sep 26, 2002
Marc,
the table is loaded. All I want to do is increment the value in the BACS_ROW_NUM column to give each row a unique id.
I was simply wondering whether someone is able to knock up a peice of SQL I could submit through SPUFI to do this. This was simply to avoid having to write a program.
Are you able to show me how to do this?
Thanks
Greg