I want to retrieve the base table name for a table and replace the table with the view name in the file.
I was trying to retrieve the base with the below db2 command but i am getting "1" as return value.
Could you anyone please assist ?
Table_name=system("db2 -x \"SELECT TRIM(TD.BSCHEMA) || \'.\' || TRIM(TD.BNAME) AS TABLE_NAME FROM SYSCAT.TABDEP TD WHERE TD.BTYPE=\'T\' AND TD.TABSCHEMA=\'XXXXXXX\' AND TD.TABNAME=\'\"$View_Name\"\' or
der by BSCHEMA desc fetch first 1 row only\"");
print Table_name;
Regards,
Nantha.Y
---------- Post updated at 05:21 AM ---------- Previous update was at 04:51 AM ----------
Hi ,
Input line : Left Outer Join XXXXXX.YYYYYYY_YYYYY_YYY
where XXXXX is VIEW_SCHEMA and YYYYY_YYYY_YY is VIEW_NAME
Objective : Replace the VIEW NAME with base table name
Output : Left Outer Join ZZZZZZ.AAAAAAA
where ZZZZZ : Base table schema
AAAAAA is Base Table name.
RudiC had made a suggestion in your other post; I'll expand on it here:
(1) Print or echo the query before passing it to DB2.
(2) Or just print it and do not pass it to DB2.
(3) When you have the query in front of you, have a close look at it. Maybe there's something wrong with it.
(4) If you think the query is correct, copy and paste it in your ad-hoc query tool (IBM Data Studio or TOAD for DB2 or whatever you are using.) Then execute it and check the result.
If you do not have a graphical tool, then run your query in the DB2 command-line processor.