Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Sybase Cursor Problem

Posted on 2004-08-26
3
Medium Priority
?
803 Views
Last Modified: 2008-03-03
Hi
I have a Requirement like this
(if (somecondition)
begin
   DECLARE EMP_CURSOR as select A1,A2 where some condition
end
(if another condition)
begin
   DECLARE EMP_CURSOR as select A1,A2 where some other condition
end
OPEN EMP_CURSOR
/* Do some processing : same for both the condions*/

This is working file if only one condition is satisfied . But if both the conditons are satisfied its giving an error
"there is already a cursor name EMP_CUR at level 1".
I don't want to move the cursor Processing code to both the if condition and duplicate it as it is very big(30 lines) .
Any help will be greatly appricciated..
0
Comment
Question by:moonoo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 29

Expert Comment

by:leonstryker
ID: 11902884
Create a variable and set its value based on the first condition being true.  Then test it if the second condition is true:

Select @con1 = 0
(if (somecondition)
begin
   Select @con1 = 1
   DECLARE EMP_CURSOR as select A1,A2 where some condition
end
(if another condition)
   if @con1 = 1
       -- Both conditions are true so the cursor needs to take that into account
   else
       begin
           DECLARE EMP_CURSOR as select A1,A2 where some other condition
       end
OPEN EMP_CURSOR
/* Do some processing : same for both the condions*/

Leon
0
 
LVL 6

Expert Comment

by:ChrisKing
ID: 11913150
could try an "ELSE IF", but you will also need to cater for neither condition being true (you won't want to process the cursor in that case).

if (somecondition)
begin
   DECLARE EMP_CURSOR as select A1,A2 where some condition
end
else if (another condition)
begin
   DECLARE EMP_CURSOR as select A1,A2 where some other condition
end

if (somecondition)
or(another condition)
begin
   OPEN EMP_CURSOR
   /* Do some processing : same for both the condions*/
end
0
 
LVL 19

Accepted Solution

by:
grant300 earned 1500 total points
ID: 11947989
The problem is that you have two conditions that are not mutually exclusive.  You actually have to code for three cases:

CASE
  WHEN {somecondition AND anothercondition} THEN
       DECLARE EMP_CURSOR .........where some condition and some other condition
  WHEN {somecondition} THEN
        DECLARE EMP_CURSOR .........where some condition
  WHEN {anothercondition} THEN
       DECLARE EMP_CURSOR ......... where some other condition
END

You can also use IF/ELSE to create unique execution paths for all three cases.

Bill
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Read on to get a few ideas on how to promote your next corporate event.
Files go missing when using DFS (Distributed File System) Replication and how to recover them and fix it.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question