View previous topic :: View next topic
|
Author |
Message |
Poha Eater
New User
Joined: 31 Aug 2016 Posts: 74 Location: India
|
|
|
|
Hi All,
Can anyone please advise me regarding a scenario for which i need to build the solution.
I have a table like below.
Code: |
ColumnA | ColumnB | ColumnC | DATE |
In the program, based upon this condition -
Code: |
IF DATE > System Date |
then run the below query :
Code: |
EXEC SQL
SELECT DATE INTO :WS-DATE FROM TABLE
WHERE ColumnA = :some value
ColumnB = :some value
ColumnC = :some value |
The issue is, in the table ColumnA, ColumnB and ColumnC values can be same. So sometimes it is having more than 1 same rows and at that time program is getting abended with duplicate rows.
I was thinking to write a cursor and fetch the value one by one but the issue is I have to fetch the value of date for each row and do some functionality if the row is present. I have to do this functionality for each row even if it is duplicate and to reach on this para which is having this query, above mentioned condition (IF DATE > System Date) should be satisfied.
So is there any way to read the duplicated row directly when coming on this query for second or third time ?
Please let me know your suggestions. Thanks. |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
This is the situation for which cursors were invented. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3053 Location: NYC,USA
|
|
|
|
If you don’t want to fail for duplicate rows then either
1. Handle -811 as a valid SQLCODE and process
2. Or write FETCH FIRST 1 ROW ONLY to this select to get one row always.
I believe the DATE value is same for all duplicated rows in that case you can use either one of the solution and if not then use CURSORS. |
|
Back to top |
|
|
Poha Eater
New User
Joined: 31 Aug 2016 Posts: 74 Location: India
|
|
|
|
Rohit Umarjikar wrote: |
If you don’t want to fail for duplicate rows then either
1. Handle -811 as a valid SQLCODE and process
2. Or write FETCH FIRST 1 ROW ONLY to this select to get one row always.
I believe the DATE value is same for all duplicated rows in that case you can use either one of the solution and if not then use CURSORS. |
Thanks for the suggestions Rohit. appreciate it. |
|
Back to top |
|
|
|