GeckoNZ
IS-IT--Management
- Jul 23, 2001
- 31
If I try to run a query while looping through a result set from another query e.g. :
$act = " SELECT account_number acct ";
$act .= " FROM acct_master ";
$Xresult = odbc_exec($conn,$accts);
while(odbc_fetch_row($Xresult))
{
$x_acct = odbc_result($Xresult,"acct");
$tran = " SELECT trans_date ";
$tran .= " FROM trans ";
$tran .= " WHERE acct = '$x_acct' ";
$Aresult = odbc_exec($conn,$tran);
$Arow = odbc_fetch_row ($Aresult);
}
I get an error like :
Warning: SQL error: , SQL state
This is running on apache with an ODBC connection to a MS SQL database. I can run individual queries just fine. It is only when I try nesting them that I have a problem. I run this type of nested query on an informix database, and MySQL databases no problems. It is only the SQL databases that give this error.
Is this a limitation of MS SQL ?
P.S. Don't take the example too seriously. It is a very simple example which I know I could fix by joining tables etc.
$act = " SELECT account_number acct ";
$act .= " FROM acct_master ";
$Xresult = odbc_exec($conn,$accts);
while(odbc_fetch_row($Xresult))
{
$x_acct = odbc_result($Xresult,"acct");
$tran = " SELECT trans_date ";
$tran .= " FROM trans ";
$tran .= " WHERE acct = '$x_acct' ";
$Aresult = odbc_exec($conn,$tran);
$Arow = odbc_fetch_row ($Aresult);
}
I get an error like :
Warning: SQL error: , SQL state
This is running on apache with an ODBC connection to a MS SQL database. I can run individual queries just fine. It is only when I try nesting them that I have a problem. I run this type of nested query on an informix database, and MySQL databases no problems. It is only the SQL databases that give this error.
Is this a limitation of MS SQL ?
P.S. Don't take the example too seriously. It is a very simple example which I know I could fix by joining tables etc.