View previous topic :: View next topic
|
Author |
Message |
ravikumar15
New User
Joined: 27 Mar 2006 Posts: 68
|
|
|
|
I have a requirement where I need to declare a cursor for the same table in two different conditions.
Condition 1:
With Where clause having only one column,
Condition 2:
When the date field in the input file is having value then include additional date field also in the where clause.
For this, I would like to pass the Cursor name to a variable and using that variable, declare the cursor after checking the date field from input file.
If the date field is blank declare, open, fetch, close Cursor-A
if the date field is non blank declare, open, fetch, close Cursor-B
Code: |
If IN-DATE-1 = SPACES
Move 'CURSOR-A' to WS-CURSOR-NAME
ELSE
Move 'CURSOR-B' to WS-CURSOR-NAME
DECLARE :WS-CURSOR-NAME
where column-1 = :ws-column1
DECLARE :WS-CURSOR-NAME
where column-1 = :ws-column1
and date-1 = :IN-DATE-1 |
Can the cursor name in DECLARE statement be a field which contains a value?
Is there any other option for this.
Any suggestion would be of great help.
Thanks in advance |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Have you considered consulting a manual for DB2 SQL?
How. Would. That. Work. ?
How would it even give you anything useful (you've missed any reasoning for why you want this)?
What problem is declaring two cursors giving you? |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
A similar question was asked a few months ago - did you search the forum? OK - it may have been another forum but a Google search may have thrown up the topic. |
|
Back to top |
|
|
ravikumar15
New User
Joined: 27 Mar 2006 Posts: 68
|
|
|
|
I tried to search in Google, but I did not get anything. If you can provide me the link, that would be great.
Thanks |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3048 Location: NYC,USA
|
|
|
|
If you try with what you did then you would know if works or gives error. Explore more on dynamic SQL.
But simple UNION will do what you want in a single cursor and if it gives any type of performance issue then follow Bills way of simply declaring two separate cursors.
Please prefer using code tags. |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Why not have two different cursor? |
|
Back to top |
|
|
|