Looks to me like you reset the $rs statement resource within one of your conditions. I've removed some of your code to try and show this. Your initial query defines the $rs statement resource, but then you reset it within the while loop.
$rs = mssql_query($SQL, $link);
while ($row = mssql_fetch_array($rs))
{
...
if ($intAreas == 0) $AreasName = "All Areas";
else
{
$SQL = "SELECT * FROM Areas where AreasID = $intAreas"; // was EarnRateName;
$rs = mssql_query($SQL, $link);
while ($rws = mssql_fetch_array($rs))
{
$AreaID = $rws['AreasID'];
$AreasName = sprintf("%s", $rws['AreasName']);
}
}
...
}
Is that what you intended to do? Seems like that could be causing the problem.
-Brian