I have a requirement where I need to check for table. If exists, drop it else do nothing. For that I written below code.
T_NAME="V_"`echo ${PARAM_BASE} | cut -d'_' -f4-`
tab_name="UV_"${T_NAME}
query_et()
{
bteq << EOBTQ | grep '^>' | sed -e "s/^>//"
.LOGON DEVEDW1/<username>,<password>;
SELECT count(*) from dbc.tables where databasename = '${SCHE_NAME}' and tablename = '${tab_name}' having count(*) > 0;
.IF ERRORCODE <> 0 THEN .QUIT 10;
.IF ACTIVITYCOUNT = 1 THEN .GOTO DROP_TAB;
.LABEL DROP_TAB;
DROP TABLE ${SCHE_NAME}.${tab_name};
.LOGOFF
.QUIT;
EOBTQ
}
The problem is, even if table does not exists, it goes to DROP statement... I do not understand why it goes there even after I put ACTIV ITY COUNT = 1. Can someonne please help me to figure out the problem?
I can't tell, as I have no command of bteq nor any idea of what values ACTIVITYCOUNT can assume nor what these represent, and what action should follow on either of those.
Did you understand what I alluded to and how you would / could change the program flow?
BTW, other languages use = for an assignment, and == for a comparison operation. You might want to check what bteq requires.
As a side note: in this case the single quotes are not relevant for the expansion, because they are situated inside an unquoted here-doc, so the variables are expanded and the results are placed inside the single quotes..
Maybe I'm missing the point, but what's wrong with ignoring the test and just trying to drop the table anyway. You can add the IF EXISTS to avoid getting error messages if it doesn't. it could be as simple as this:-
DROP TABLE IF EXISTS ${TABLE_NAME} ;
I hope that this helps, but I apologise if I've missed the point.
Robin