Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Por que essa mensagem de erro?
>
ADODB.Recordset erro '800a0bb9'
Os argumentos são incorretos, estão fora do intervalo aceitável ou estão em conflito.
/dicas sql/pivot_soma_por_ano.asp, linha 19
O código é esse:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--#include file="conexaodbdicas.asp"-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<%
strSql = " SELECT "
strSql = strSql & " IFNULL(EMPid,'Totals') AS Empid, "
strSql = strSql & " sums.2005, sums.2006, sums.2007, sums.2005 + sums.2006 + sums.2007 AS Sums "
strSql = strSql & " FROM (SELECT EmpID, SUM(IF(Yr=2005,sales,0)) AS '2005', "
strSql = strSql & " SUM(IF(Yr=2006,sales,0)) AS '2006', "
strSql = strSql & " SUM(IF(Yr=2007,sales,0)) AS '2007' "
strSql = strSql & " FROM Sales GROUP BY EmpID WITH ROLLUP) AS sums"
set rs=Server.CreateObject("ADODB.RecordSet")
rs.Open strSql, cn
%>
</head>
<body>
<table width="50%" border="1" cellpadding="1" cellspacing="0">
<thead>
<tr align="center" bgcolor="#999999">
<th>EmpId</th>
<th>2005</th>
<th>2006</th>
<th>2007</th>
<th>Sums</th>
</tr>
<%
if not rs.eof then
do while not rs.eof
%>
<tr>
<td><%=rs("empId")%></td>
<td><%=rs("2005")%></td>
<td><%=rs("2006")%></td>
<td><%=rs("2007")%></td>
<td><%=rs("sums")%></td>
</tr>
<%
rs.MoveNext
Loop
end if
%>
</thead>
</table>
</body>
</html>
Na área do MySQL mostra perfeitamente com a sintaxe;
SELECT
IFNULL(EMPid, 'Totals') AS Empid,
sums.2005, sums.2006, sums.2007,
sums.2005 + sums.2006 + sums.2007 AS Sums
FROM (
SELECT
EmpID,
SUM(IF(Yr=2005,sales,0)) AS '2005',
SUM(IF(Yr=2006,sales,0)) AS '2006',
SUM(IF(Yr=2007,sales,0)) AS '2007'
FROM Sales
GROUP BY EmpID WITH ROLLUP
) AS SUMS;Carregando comentários...