I ran into this probelm with my query
The following are my codes:
$conn=mssql_connect($DataSource,$UserId,$Password) or die("Couldn't connect to server.");
mssql_select_db($InitialCatalog,$conn);
$sSQL=
"IF '$sAgentID' IN (SELECT AgentID FROM telecom1.Agents) "."\r\n".
" SELECT pathLogoImage, "."\r\n".
" CompanyName, "."\r\n".
" Address, "."\r\n".
" City, "."\r\n".
" State, "."\r\n".
" Zip, "."\r\n".
" Phone, "."\r\n".
" Fax, "."\r\n".
" CompanyEmail, "."\r\n".
" CompanyURL "."\r\n".
" FROM telecom1.Agents "."\r\n".
" WHERE AgentID = '$sAgentID'"."\r\n".
"ELSE "."\r\n".
" SELECT TOP 1 "."\r\n".
" pathLogoImage, "."\r\n".
" CompanyName, "."\r\n".
" Address, "."\r\n".
" City, "."\r\n".
" State, "."\r\n".
" Zip, "."\r\n".
" Phone, "."\r\n".
" Fax, "."\r\n".
" CompanyEmail, "."\r\n".
" CompanyURL "."\r\n".
" FROM telecom1.Agents "."\r\n".
" WHERE Left(AgentID,3) = "."'".substr($sAgentID,0,3)."'"."\r\n".
" ORDER BY AgentID"."\r\n";
$rs=mssql_query($sSQL,$conn);
echo mssql_result($rs,0,"CompanyName");
I got the following error:
mssql_result(): supplied argument is not a valid MS SQL-result resource
However if I take out the "if-else" statement and only use top half of the query everything is fine as follows:
$sSQL=
" SELECT pathLogoImage, "."\r\n".
" CompanyName, "."\r\n".
" Address, "."\r\n".
" City, "."\r\n".
" State, "."\r\n".
" Zip, "."\r\n".
" Phone, "."\r\n".
" Fax, "."\r\n".
" CompanyEmail, "."\r\n".
" CompanyURL "."\r\n".
" FROM telecom1.Agents "."\r\n".
" WHERE AgentID = '$sAgentID'"."\r\n";