Building SQL update statements using a Bash script

前端 未结 2 1330
一向
一向 2021-01-29 07:39

For a recent project I need to loop through rows of a csv (ignore.csv) with 3 columns:

acctnum, errcode, date ← in that order…

(Column naming doesn\

2条回答
  •  孤独总比滥情好
    2021-01-29 08:04

    You're overwriting the file every time you echo inside the loop. Move the output redirection to the end of the loop.

    while IFS=, read -r field1 field2 field3;
    do
       echo "UPDATE ODS.PERF_ACCT_ERR_DTL SET REC_ACTV_IND='T' WHERE BUS_DT='$field3' and ETL_ERR_CD='$field2' AND ACCT_KEY in (SELECT ACCT_KEY FROM ODS.ACCT_PORTFOLIO WHERE ACCT_SRCH_NBR='$field1');"
    done < ignore.csv > sqlfile.txt
    

提交回复
热议问题