in reply to SQL While loop problem.

Unrelated to your actual questions, there are two easy things you can improve in your code:

If you're doing an error check after each database operation anyway, you might just as well set the RaiseError => 1 option during connect. That way you save a whole lot of redundant error check code.

if ($mth eq "01") {$monnm = "January"}; if ($mth eq "02") {$monnm = "February"}; if ($mth eq "03") {$monnm = "March"}; if ($mth eq "04") {$monnm = "April"}; if ($mth eq "05") {$monnm = "May"}; if ($mth eq "06") {$monnm = "June"}; if ($mth eq "07") {$monnm = "July"}; if ($mth eq "08") {$monnm = "August"}; if ($mth eq "09") {$monnm = "September"}; if ($mth eq "10") {$monnm = "October"}; if ($mth eq "11") {$monnm = "November"}; if ($mth eq "12") {$monnm = "December"};

I'd write that as

my @months = qw/January February March April May June July August Sept +ember October November Decemeber/; # arrays are zero-indexed, so subtract one to # get from the month number to the array index: $monnm = $months[$mnth - 1];