Hola gente,
Tengo la siguiente consulta que me funciona muy bien en el sql-server
Código SQL:
Ver originalSELECT CONVERT(VARCHAR(8), G.[GradedDate] , 108) AS 'Time',
CONVERT(VARCHAR(MAX),G.[VisitorNumber]) + '/' + CONVERT(VARCHAR(MAX),G.[HomeNumber]) AS 'NumGame', G.[VisitorTeam] + ' @ ' +G.[HomeTeam] AS 'Teams',
P.[PeriodDescription], CONVERT(VARCHAR(MAX),G.[VisitorScore]) + ' - ' + CONVERT(VARCHAR(MAX),G.[HomeScore]) AS 'Score', COUNT(*) AS 'Tickets',
SUM(H.[RiskAmount]) AS 'Risk'
FROM WAGERHEADER H, WAGERDETAIL D, GAME G, PERIOD P
WHERE H.[IdWager] = D.[IdWager] AND
D.[IdGame] = G.[IdGame] AND
H.[SettledDate] >= CONVERT(datetime,('2014-01-10 00:00:01')) AND
H.[SettledDate] <= CONVERT(datetime,('2014-01-10 23:59:59')) AND
D.[IdSport] = P.[IdSport] AND
D.[Period] = P.[NumberOfPeriod] AND
H.[IdAgent] = 7
GROUP BY G.[GradedDate], G.[VisitorNumber], G.[VisitorTeam], G.[HomeNumber], G.[HomeTeam], P.[PeriodDescription], G.[VisitorScore], G.[HomeScore]
Pero cuando la realizo desde el php me da este error:
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[24000]: Invalid cursor state: 0 [FreeTDS][SQL Server]Invalid cursor state (SQLExecute[0] at /build/php5-UepG4H/php5-5.3.3/ext/pdo_odbc/odbc_stmt.c:254)' in /var/www/gradingticker/v1/class/search.php:48\nStack trace:\n#0 /var/www/gradingticker/v1/class/search.php(48): PDO->query('SELECT CONVERT(...')\n#1 {main}\n thrown in /var/www/gradingticker/v1/class/search.php on line 48, referer: http://gradingticker.evenreal.com/index.php
Este es mi codigo PHP:
Código PHP:
Ver original$yesterday = date('Y-m-d')." 00:00:01"; $today = date('Y-m-d')." 23:59:59";
$strQueryGames = "SELECT CONVERT(VARCHAR(8), G.[GradedDate] , 108) AS 'Time',
CONVERT(VARCHAR(MAX),G.[VisitorNumber]) + '/' + CONVERT(VARCHAR(MAX),G.[HomeNumber]) AS 'NumGame', G.[VisitorTeam] + ' @ ' +G.[HomeTeam] AS 'Teams', P.[PeriodDescription],
CONVERT(VARCHAR(MAX),G.[VisitorScore]) + ' - ' + CONVERT(VARCHAR(MAX),G.[HomeScore]) AS 'Score', COUNT(*) AS 'Tickets',
SUM(H.[RiskAmount]) AS 'Risk'
FROM WAGERHEADER H, WAGERDETAIL D, GAME G, PERIOD P
WHERE H.[IdWager] = D.[IdWager] AND
D.[IdGame] = G.[IdGame] AND
H.[SettledDate] >= CONVERT(datetime,('".$yesterday."')) AND
H.[SettledDate] <= CONVERT(datetime,('".$today."')) AND
D.[IdSport] = P.[IdSport] AND
D.[Period] = P.[NumberOfPeriod] AND
H.[IdAgent] = ".$IdAgent."
GROUP BY G.[GradedDate], G.[VisitorNumber], G.[VisitorTeam], G.[HomeNumber], G.[HomeTeam], P.[PeriodDescription], G.[VisitorScore], G.[HomeScore]";
error_log("class->search.php->strQueryGames = ".$strQueryGames); $strDataGames = $strConnect->query( $strQueryGames );
while($dataGames = $strDataGames->fetch(PDO::FETCH_ASSOC)){
$response = "<tr>";
$response .= "<td>".$dataGames['Time']."</td>";
$response .= "<td>".$dataGames['NumGame']."</td>";
$response .= "<td>".$dataGames['Teams']."</td>";
$response .= "<td>".$dataGames['PeriodDescription']."</td>";
$response .= "<td>".$dataGames['Score']."</td>";
$response .= "<td>".$dataGames['Tickets']."</td>";
$response .= "<td>".$dataGames['Risk']."</td>";
$response .= "<td>-275</td>";
$response .= "<td>-17517</td>";
$response .= "<td><a href='#' rel='".$_POST['value']."' onClick='openInfoAgent(this);'>".$_POST['value']."</a></td>";
$response .= "</tr>";
}
Alguna ayudita con este error?