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
Solved

Sybase Cursor Problem

Posted on 2004-08-26
3
773 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
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 500 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sybase memory in corresponds to sybase pagesize 4 1,356
How would you store an Access 2003 memo data type field in Sybase. 1 562
SyBase SQL Querry Syntax 1 266
SyBase SQL Query 7 166
Most MSPs worth their salt are already offering cybersecurity to their customers. But cybersecurity as a service is wide encompassing and can mean many things.  So where are MSPs falling in this spectrum?
There's a lot of hype surrounding blockchain technology. Here's how it works and some of the novel ways it' s now being used - including for data protection.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

861 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