Procedure SQL Serve c/ ASP

Asked

Viewed 43 times

1

good afternoon! I have this basic process in SQL Server, which brings me the spending percentage:

DECLARE 
    @totalDespesas       FLOAT
    ,@totalDespesasAcomp FLOAT
    ,@resultado          FLOAT  

    SET @totalDespesas      = (SELECT SUM(valorReal) FROM dbo.contasRatear)
    SET @totalDespesasAcomp = (SELECT SUM(valorReal) FROM dbo.contasRatear WHERE acompanhar = 'SIM')
    SET @resultado          = ROUND(((@totalDespesasAcomp / @totalDespesas) * 100),2)

SELECT @resultado as totalperc

Upon receiving the result value in ASP, error appears: "O_item_não_pode_ser_encontrado_na_coleção_correspondente_ao_nome_ou_ao_ordinal_solicitado."

ASP/HTML:

                                <%
                                    sql = "EXEC despesasRatearBuscaPercentualDespesas;"
                                    set bd = Conn.execute(sql)
                                %>
                                <th colspan="1" style="text-align:center" id="" class=""><%=bd("totalperc")%>%</th>

Can you help me? Thank you :)

  • It seems to me you’re not finding some column that you put in the past.

  • Thank you, but the column is, 'totalperc'...

  • The connection is open?

  • Yes open connection.

  • Any other trial works normally. Recovers the "Fields"... I believe the problem is in this my trial...

1 answer

0

What may be occurring is that Procedure may not be returning the result. Try to do it this way:

<%
sql = "EXEC despesasRatearBuscaPercentualDespesas"
set bd = Conn.execute(sql)
if not bd.eof then
%>
<th colspan="1" style="text-align:center" id="" class=""><%=bd.fields("totalperc")%>%</th>
<%
else
response.write("Não retornou informações")
end if
%>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.