Shell Scripting question with SQL

hey i have to connect to sql through shell script , then store the value of the query in a variable and then compare it after some time after running a process.
i have used this code but it is not working.

#!/bin/sh
Val = (sqlplus -s rte/rted2@rel76d2 <<!
 SELECT MAX(STAT_ID) FROM CVT_STATS;
!)
echo $Val
nohup ./cvt -f MediationSources.xml &

sleep 60

Val1 = (sqlplus -s rte/rted2@rel76d2 << !
SELECT MAX(STAT_ID) FROM CVT_STATS;
!)
if[$Val ==$Val1]; then
   echo FAIL
else
   echo PASS
fi

but it is not working can any please help me

you have to include the command in back quotes

 
#!/bin/sh
Val = `sqlplus -s rte/rted2@rel76d2 <<!
SELECT MAX(STAT_ID) FROM CVT_STATS;
!`
echo $Val
nohup ./cvt -f MediationSources.xml &

sleep 60

Val1 = `sqlplus -s rte/rted2@rel76d2 << !
SELECT MAX(STAT_ID) FROM CVT_STATS;
!`
if [ $Val == $Val1 ]; then
echo FAIL
else
echo PASS
fi


Add dollar and removes spaces before and after equal sign. Also in If statement add space between variable and bracket

#!/bin/sh
Val=$(sqlplus -s rte/rted2@rel76d2 <<!
 SELECT MAX(STAT_ID) FROM CVT_STATS;
!)
echo $Val
nohup ./cvt -f MediationSources.xml &

sleep 60

Val1=$(sqlplus -s rte/rted2@rel76d2 << !
SELECT MAX(STAT_ID) FROM CVT_STATS;
!)
if[ $Val == $Val1 ]; then
   echo FAIL
else
   echo PASS
fi

Few more changes that I would like to suggest:

Set the heading OFF before querying:

Val=$(sqlplus -s rte/rted2@rel76d2 <<!
set head off
 SELECT MAX(STAT_ID) FROM CVT_STATS;
!)

Use -eq operator instead of == operator for numeric comparison:

if[ $Val -eq $Val1 ]