I would recommend:
- Use DBI and DBD::ODBC rather than Win32::ODBC. It'll make things a lot easier in the long run (this is from experience)
- Use use strict;
- Use use CGI::Carp "fatalsToBrowser";
And after you do
$sql=... do a
print "SQL=$sql" bit so you can visually see what exactly is being processed.