in reply to Returning a value from a sub routine

Your code does not specify which database to use on the sybase server. Most likely is that your connection succeeded, but defaults to the master database. A quick fix is to specify the name of the database in the $SQLDT like below:

select max(convert(char(12), Modified_Date, 101)) from databasename..Metrics

Assumes that you are using ASE of course.