Friday, May 29, 2009

SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]The FOR XML clause is not allowed in a CURSOR statement

If your sql query is something like
$sqlQuery = “select * from test for xml raw('MyItem'), elements, root('MyRoot')”;

As a work around you can wrap it inside another select statement.
$sqlQuery = "select (" . $sqlQuery . ")";

This query will return the record set containing only one row and one column and which will be your xml. You can get the xml by using odbc_result($queryResult,1);

If the xml is too big you may need to configure max_execution_time, memory_limit and odbc.defaultlrl in the php.ini file according to your requirement.

3 comments:

  1. plz check my pc

    ReplyDelete
  2. @Anonymous: Please tell me the issue you face or the error message. I could not understand anything much from your comment.

    ReplyDelete