gregsimpson
Programmer
- Apr 18, 2002
- 521
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
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