Hi ghostdog74,
Thank you so much for your advise.
The code become so messy and difficult to read after I copy it into here.

So sorry about it.
I added in the closing pair for EOFMYSQL and tried to execute the script. The same error still prompt out.
Is it ok to load the data into databse by using Case statement?
Tried to execute the script by sh -x statbackup.ksh, but it didnt show where is the error, just prompt "unexpected end of file". Please advise.
Thank you so much.
Br,
Shirley