473,385 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

MORE sql Query

I can't write the sum of a certain colum in a table of a db.

<%
sql_Sum_Tax="SELECT SUM(vtax) AS sql_Sum_Tax_RS_Var FROM orderstats
WHERE vcompletedate BETWEEN "& startDate &" AND "& endDate & ";"
Set sql_Sum_Tax_RS = Server.CreateObject("ADODB.Recordset")
sql_Sum_Tax_RS.Open sql_Sum_Tax, conn1
%>
<%=sql_Orders_Placed_RS("sql_Orders_Placed_RS_Var" )%>

That last line generates this error:

ADODB.Recordset error '800a0cc1'

Item cannot be found in the collection corresponding to the requested
name or ordinal.

Suggestions? Thanks
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #1
6 1680
http://www.adopenstatic.com/faq/800a0cc1.asp

You need to show us the code that produces the field
sql_Orders_Placed_Rs_Var

since the following line generates the error:
<%
sql_Orders_Placed_RS("sql_Orders_Placed_RS_Var")
%>

Cheers
Ken
"Jason Daly" <da********@yahoo.com> wrote in message
news:Oz**************@TK2MSFTNGP12.phx.gbl...
: I can't write the sum of a certain colum in a table of a db.
:
: <%
: sql_Sum_Tax="SELECT SUM(vtax) AS sql_Sum_Tax_RS_Var FROM orderstats
: WHERE vcompletedate BETWEEN "& startDate &" AND "& endDate & ";"
: Set sql_Sum_Tax_RS = Server.CreateObject("ADODB.Recordset")
: sql_Sum_Tax_RS.Open sql_Sum_Tax, conn1
: %>
: <%=sql_Orders_Placed_RS("sql_Orders_Placed_RS_Var" )%>
:
: That last line generates this error:
:
: ADODB.Recordset error '800a0cc1'
:
: Item cannot be found in the collection corresponding to the requested
: name or ordinal.
:
: Suggestions? Thanks
:
:
: *** Sent via Developersdex http://www.developersdex.com ***
: Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #2
I am new to aggregate functions. I thought i was moving in the right
direction when writing:

<%
sql_Sum_Tax="SELECT SUM(vtax) AS sql_Sum_Tax_RS_Var FROM orderstats
WHERE vcompletedate BETWEEN "& startDate &" AND "& endDate & ";"
Set sql_Sum_Tax_RS = Server.CreateObject("ADODB.Recordset")
sql_Sum_Tax_RS.Open sql_Sum_Tax, conn1
%>

I never defined or declared sql_Sum_Tax_RS_Var. I thought I was just
allowed to use the AS keyword that way, and then I could write the SUM
with:

<%
response.write sql_Sum_Tax_RS("sql_Sum_Tax_RS_Var")
%>

How do I properly write a sql statement and response.write statement
that will allow me to write the SUM of a field?

**My original response.write statement was mispasted.**

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #3
Jason Daly wrote:
I am new to aggregate functions. I thought i was moving in the right
direction when writing:

<%
sql_Sum_Tax="SELECT SUM(vtax) AS sql_Sum_Tax_RS_Var FROM orderstats
WHERE vcompletedate BETWEEN "& startDate &" AND "& endDate & ";"
Set sql_Sum_Tax_RS = Server.CreateObject("ADODB.Recordset")
sql_Sum_Tax_RS.Open sql_Sum_Tax, conn1
%>

I never defined or declared sql_Sum_Tax_RS_Var. I thought I was just
allowed to use the AS keyword that way, and then I could write the SUM
with:

<%
response.write sql_Sum_Tax_RS("sql_Sum_Tax_RS_Var")
%>

This should work correctly, although I can never understand why people want
to use such god-awfully long names when a simple name like SumVtax would do.
Practicing your typing skills? Exercising that finger that types the
underscore, maybe? :-)

Moreover, why would you want to use a variable name like sql_Sum_Tax_RS
when a simple rs would do? You did not bother ultra-defining the conn1
variable did you? Actually, the "1" in that name makes me a little nervous -
are you opening more than one connection to your database on this page?
There is never a good reason to do this. A single connection can be re-used
as many times as you want. There is no need to open a new connection for
each task ...

Anyways, back to referencing the field name: there are several ways to refer
to a recordset field:

1. The most efficient is by using the zero-based ordinal position number.
The first field in the recordset has an ordinal position of zero, and so on.
So you can use rs(0) to refer to it.
The value in the parentheses must either be a literal number (no quotes) or
a variable or constant containing a number:
i=1
rs(i) 'refers to second field in recordset

2. You can use the field's name, which will either contain the actual name
of the database column, or the column alias assigned to the field in the sql
query. Again, you can either use a literal string surrounded by quotes:
rs("fieldname")
or a variable containing a string:
s="fieldname"
rs(s)

It's a good idea to explicitly state the property you wish to access to
avoid errors. To get the value of a field, explicitly use the word "value"
in your statement:

var = rs(0).value

Back to this:
response.write sql_Sum_Tax_RS("sql_Sum_Tax_RS_Var")

Given that your sql statement contains this:
" ... AS sql_Sum_Tax_RS_Var ... "

and you have no typos (whose frequency will be increased by the complicated
names you are using <grin>), then this should work fine. Since it is not
working fine, you need to determine the actual names of the fields in your
recordset:

for i = 0 to sql_Sum_Tax_RS.Fields.Count
response.write i & ": " & _
sql_Sum_Tax_RS(i).Name & "<BR>"
next

Again, given the complicated names you are using for your variables and
aliases, I would not be at all surprised if your code contained a typo.

Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #4
That code should work...

Can you try doing this:
<%
response.write sql_Sum_Tax_RS(0)
%>
and see if that also generates an error?

We can also try to verify what the recordset thinks are the names of the
fields by doing:

<%
sql_Sum_Tax_RS.Open <your stuff here>

Response.Write("<u>Outputting Field Names</u><br />")
For Each objField in sql_Sum_Tax_RS.Fields

Response.Write(objField.Name & "<br />")

Next
%>

I think it should output: sql_Sum_Tax_RS_Var, but let's have a look and see.

Cheers
Ken
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"Jason Daly" <da********@yahoo.com> wrote in message
news:ef**************@TK2MSFTNGP09.phx.gbl...
: I am new to aggregate functions. I thought i was moving in the right
: direction when writing:
:
: <%
: sql_Sum_Tax="SELECT SUM(vtax) AS sql_Sum_Tax_RS_Var FROM orderstats
: WHERE vcompletedate BETWEEN "& startDate &" AND "& endDate & ";"
: Set sql_Sum_Tax_RS = Server.CreateObject("ADODB.Recordset")
: sql_Sum_Tax_RS.Open sql_Sum_Tax, conn1
: %>
:
: I never defined or declared sql_Sum_Tax_RS_Var. I thought I was just
: allowed to use the AS keyword that way, and then I could write the SUM
: with:
:
: <%
: response.write sql_Sum_Tax_RS("sql_Sum_Tax_RS_Var")
: %>
:
: How do I properly write a sql statement and response.write statement
: that will allow me to write the SUM of a field?
:
: **My original response.write statement was mispasted.**
:
: *** Sent via Developersdex http://www.developersdex.com ***
: Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #5
All set...for some reason (NOT a typo) my field names still were showing
null. RS(0) worked though. Thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #6
Jason Daly wrote:
All set...for some reason (NOT a typo) my field names still were
showing null. RS(0) worked though. Thanks.

If your sql statement had column aliases then this is simply not possible.
If you're still around, would you mind using the recordset's Save method,

rs.Save "filename",1

to save your recordset to a file and post the text contained in the file (no
need to attach the file, just open it in notepad and copy the text) to your
reply?

Oh! What database are you using?

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Wescotte | last post by:
Here is a small sample program I wrote in PHP (running off Apache 1.3.31 w/ PHP 5.0.1) to help illustrates problem I'm having. The data base is using DB2 V5R3M0. The client is WinXP machine using...
4
by: Shufen | last post by:
Hi, I'm a newbie that just started to learn python, html and etc. I have some questions to ask and hope that someone can help me on. I'm trying to code a python script (with HTML) to get...
6
by: Ryan | last post by:
I have a query which is quite complex. It's based on a set of data in a complex view which takes the data from several tables. In this complex query, if I allow the various parts of the query to...
2
by: Good Man | last post by:
Hi there Yes, I've read about JOINs, albeit after coding for a couple of years already using queries like the following: "SELECT m.LastName, m.FirstName, o.Address FROM members m, offices o...
4
by: Ray | last post by:
I need to create a report showing the candidate, class, score of judge 1, 2, 3, 4. Currently, I manage to obtain the result of candidate and score of judge 1, 2, 3 and 4 but not the class. I would...
4
by: Bob Alston | last post by:
Some more, rather specific Access performance questions. IN a split front-end & back-end Access/Jet ONLY LAN situation, and with all query criteria fields and join fields indexed: 1. Is is...
4
by: Kathy | last post by:
I have a query that is being created in code. When the query is executed I get the error: "The specified field 'Acct' could refer to more than one table listed in the FROM clause". As you can...
7
by: mp | last post by:
No value given for one or more required parameters. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information...
0
by: Gordon.E.Anderson | last post by:
short description: i've got a .net web site set up using a tableadapter attached to a sql server table - returning results only, no update of data. i've got a query (qry code below) set up to...
3
by: Ken Fine | last post by:
This is a question that someone familiar with ASP.NET and ADO.NET DataSets and DataTables should be able to answer fairly easily. The basic question is how I can efficiently match data from one...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.