I am trying to declare cursor based on if else condition in Pro C program and receiving below error when I tried below logic.
I know why it's giving me the below warning but my concern is this approach isn't functioning as expected when I try to open cursor and perform processing based on sqlcode received.
I think we can create two separate cursors then open an one based on the if else condition but just wanted to check if there is any other solution to this?
if(is_valid[0] == 'Y')
{
EXEC SQL DECLARE cust CURSOR FOR
select customer, id, price from table1;
}
else
{
EXEC SQL DECLARE cust CURSOR FOR
select customer, id, price from table2;
}
}
Error:
PCC-W-02332, attempted to redefine SQL identifier
It looks like the problem is using
DECLARE custtwice.From the Advanced Pro*C/C++ documentation [untested]:
You can try declaring the variable and then passing the declared cursor variable in as a bind variable: