我是Teradata的新手。我的BTEQ计划有问题。 BTEQ作业传递变量shell脚本。程序的目的是检查摘要表中延迟2个月的任何空值。下面是该表的一个示例(程序的目的:当Summary表缺少两个月时,例如,Oct和Nov则flag = Y.flag = Y表示YES表示在Summary表中有空值十月和十一月.flag = N表示没有空值):
dt_load maxmth summary
12-SEP Sep Sep
13 SEP Sep
29-SEP Sep
2-Oct Oct
3-Oct Oct
1-Nov Nov
2-Nov Nov
user="usr1"
pass="pass1"
SRC_DB="emp"
SOURCE_TABLE="summarytb"
FLAG =$(query_td)
td_query () { bteq << EOF |grep '^>' |sed -e "s/^>//"
${HOST}/${USER},${PASSWORD}
DATABASE $SRC_DB;
.set width 1000;
.set titledashes off;
SELECT COUNT(*)
FROM ${SRC_DB}.${SOURCE_TABLE};
( SELECT
dt_load,
summary ,
maxmth,
/*check for null 2 months back*/
MDIFF(summary, 2, maxmth, dt_load) AS diff1
FROM $SOURCE_TABLE
Group by dt_load) AS a
FROM
/*if summary field is null than insert 2*/
( SELECT *,
COALESCE(a.diff1,2) AS diff (Select FROM a) AS b
FROM
/* if diff= 2 than flag =Y else flag=N*/
( SELECT *,
CASE
When b.diff = 2 then ‘Y ‘ ELSE ‘N’
End ) AS flag (SELECT c.diff FROM b) c
FROM
/*pass flag variable to shell script*/
SELECT '>'||' c.flag';
$1
.LOGOFF;
.QUIT;
.EXIT
EOF
}
echo $FLAG
if [ $FLAG='Y' ] then echo Run file1;
exit 1
fi
IF [ $FLAG='N' ] then echo run file 2;
exit 1
fi