473,396 Members | 1,849 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,396 software developers and data experts.

Nested MSAccess Union-Queries in asp

Hi,

I'm trying to run a nested (UNION) query against a MSAccessXP database
(version 2002; build 10.6501.6714; SP3)
In Access the SQL-statement executes just fine. When I run it in a asp-page
I get the following error:
Microsoft JET Database Engine (0x80040E10)
No value given for one or more required parameters.

Can a nested union-query be used at all or should I use an intermediate
table?

Thanks,
Djurre

Below are the details of the sql I want to use.

The query sums the competition results for several teams.
I have one table with the team-codes. This table is joined with the
match-results for home and away-games.
For home-games the team-code is record in the column game.home-team and for
away-games the team-code is recorded in the column game.away-team.
Per team I want to list: sort-code, team-code, team-name, games played,
wins, draws, losses, points, goals scored, goals against

The sql statement I want to use is like this:
Select
SELECT Teams.[Sort-code], Teams.[Team-code], Teams.[Team-name], sum(played)
AS games, sum(w) AS Wins, sum(D) AS Draws, sum(L) AS Losses, sum(GP) AS
Gamepoints, sum(For) AS GF, sum(Against) AS GA
FROM (
SELECT
Teams.[Sort-code], Teams.[Team-code], Teams.[Team-name],
count(*) as Played,
sum(Iif( WT.[goals-home] > WT.[goals-away] , 1, 0)) as W,
sum(Iif( WT.[goals-home] = WT.[goals-away] , 1, 0)) as D,
sum(Iif( WT.[goals-home] < WT.[goals-away] , 1, 0)) as L,
sum(Iif( WT.[goals-home] > WT.[goals-away] , 3, Iif(WT.[goals-away] =
WT.[goals-away], 1, 0))) as GP,
sum(WT.[goals-home]) as For,
sum(WT.[goals-away]) as Against
FROM
Teams
left outer JOIN Games as WT ON (Teams.[Team-code] = WT.[Team-code home] and
WT.[Status]="2")
Group by Teams.[Sort-code], Teams.[Team-code], Teams.[Team-name]

UNION

SELECT
Teams.[Sort-code], Teams.[Team-code], Teams.[Team-name],
count(*) as Played,
sum(Iif( WU.[goals-home] < WU.[goals-away] , 1, 0)) as W,
sum(Iif( WU.[goals-home] = WU.[goals-away] , 1, 0)) as D,
sum(Iif( WU.[goals-home] > WU.[goals-away] , 1, 0)) as L,
sum(Iif( WU[goals-home] < WU.[goals-away] , 3, Iif(WT.[goals-away] =
WT.[goals-away], 1, 0))) as GP,
sum(WU.[goals-away]) as For,
sum(WU.[goals-home]) as Against
FROM
Teams
left outer JOIN Games as WU ON (Teams.[Team-code] = WU.[Team-code away] and
WU.[Status]="2")
Group by Teams.[Sort-code], Teams.[Team-code], Teams.[Team-name]
)

GROUP BY Teams.[Sort-code], Teams.[Team-code], Teams.[Team-name]
ORDER BY Teams.[Sort-code];


Jul 22 '05 #1
2 2146
I'm surprised it runs in Access without an alias for the subquery. The basic
syntax should be:

Select q.col1,...,q.colN FROM (select ...) As q

Personally, I would put the whole thing into a saved query and execute the
saved query from asp:

set rs=createobject("adodb.recordset")
conn.NameOfSavedQuery rs

ADO allows you to run a stored procedure/saved query by treating it as if it
was a builtin method of the Connection object. If the saved query accepts
parameters, then you simply supply them as if they were arguments for the
method:

set rs=createobject("adodb.recordset")
conn.NameOfSavedQuery parm1,...,parmN, rs

And if the query does not return records, simply leave off the recordset
variable:
conn.NameOfSavedQuery parm1,...,parmN

See here for a little more:
http://www.google.com/groups?selm=eE...&output=gplain -

I just noticed something else. See below:

d2r2 wrote:
Hi,

I'm trying to run a nested (UNION) query against a MSAccessXP database
(version 2002; build 10.6501.6714; SP3)
In Access the SQL-statement executes just fine. When I run it in a
asp-page I get the following error:
Microsoft JET Database Engine (0x80040E10)
No value given for one or more required parameters.

Can a nested union-query be used at all or should I use an
intermediate table?
<snip> Select
SELECT
This also seems suspicious. Two SELECT keywords in a row???
Teams.[Sort-code], Teams.[Team-code], Teams.[Team-name],
sum(played) AS games, sum(w) AS Wins, sum(D) AS Draws, sum(L) AS
Losses, sum(GP) AS Gamepoints, sum(For) AS GF, sum(Against) AS GA
FROM ( <snip> )
See? No alias. The query engine does not know what is meant by "Teams." in
your SELECT, GROUP BY and WHERE clauses. You need to put

As Teams

here.
GROUP BY Teams.[Sort-code], Teams.[Team-code], Teams.[Team-name]
ORDER BY Teams.[Sort-code];


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 22 '05 #2
Bob,
thanks for your pointers.
I noticed the typo (select select) too. I began to type in the statement and
then pasted it in anyway.

Initially I tried using a saved query but that didn't work as I connect thru
a DSN on the hosting service supplier webserver I use.
Locally the saved query does work thru IIS/Microsoft.Jet.OLEDB.4.0.

Found the bug.
In the asp-version of the sql-statement I included a "+" too many. Removed
that , and now it works just fine.

thanks again,
Djurre
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I'm surprised it runs in Access without an alias for the subquery. The
basic syntax should be:

Select q.col1,...,q.colN FROM (select ...) As q

Personally, I would put the whole thing into a saved query and execute the
saved query from asp:

set rs=createobject("adodb.recordset")
conn.NameOfSavedQuery rs

ADO allows you to run a stored procedure/saved query by treating it as if
it was a builtin method of the Connection object. If the saved query
accepts parameters, then you simply supply them as if they were arguments
for the method:

set rs=createobject("adodb.recordset")
conn.NameOfSavedQuery parm1,...,parmN, rs

And if the query does not return records, simply leave off the recordset
variable:
conn.NameOfSavedQuery parm1,...,parmN

See here for a little more:
http://www.google.com/groups?selm=eE...&output=gplain -

I just noticed something else. See below:

d2r2 wrote:
Hi,

I'm trying to run a nested (UNION) query against a MSAccessXP database
(version 2002; build 10.6501.6714; SP3)
In Access the SQL-statement executes just fine. When I run it in a
asp-page I get the following error:
Microsoft JET Database Engine (0x80040E10)
No value given for one or more required parameters.

Can a nested union-query be used at all or should I use an
intermediate table?

<snip>
Select
SELECT


This also seems suspicious. Two SELECT keywords in a row???
Teams.[Sort-code], Teams.[Team-code], Teams.[Team-name],
sum(played) AS games, sum(w) AS Wins, sum(D) AS Draws, sum(L) AS
Losses, sum(GP) AS Gamepoints, sum(For) AS GF, sum(Against) AS GA
FROM (

<snip>
)


See? No alias. The query engine does not know what is meant by "Teams." in
your SELECT, GROUP BY and WHERE clauses. You need to put

As Teams

here.

GROUP BY Teams.[Sort-code], Teams.[Team-code], Teams.[Team-name]
ORDER BY Teams.[Sort-code];


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 22 '05 #3

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

Similar topics

2
by: Jim | last post by:
Im getting way too many rows retured..what its trying to do is insert a 0 for revenue for months 7 - 12 (aka July through December) for each of these cost centers for each payor type..Im getting a...
0
by: Chi | last post by:
This is a problem that has been nagging me for a while, and I cannot figure out how to best solve the problem: I have a stored procedure that returns multi-level "nested" XML and inline XDR. My...
3
by: Ker | last post by:
I have a query that works great. It gives me the min for multiple fields. Within this query, I also need to get the max of some fields too. I currently have output of Date Name ...
15
by: (Pete Cresswell) | last post by:
I've got a .BAT file that I use for executing various MS Access apps that I wrote way back in the days of 2.0. It's evolved over time, but it still contains a number of possible paths to...
10
by: tapeesh | last post by:
I created a C file say struct.c with the following structure declarations in the same file struct A { union key { int i; float f; }k1;
11
by: Alfonso Morra | last post by:
Hi, I have the ff data types : typedef enum { VAL_LONG , VAL_DOUBLE , VAL_STRING , VAL_DATASET }ValueTypeEnum ;
0
by: rgettman | last post by:
Hello, I'm attempting to use Pro*C to create a nested table and send that data to a stored procedure as a parameter. However, I'm getting a Pro*C compiler error that I'll describe below. I'm...
1
by: borophyll | last post by:
The C standard talks about nested declarators, and th only example of nested declarators I can think of are function parameter declarations, which are nested within the function declaration. Are...
0
by: bbrewder | last post by:
I am struggling with some MSAccess automation issues. Basically, we have a .Net application that uses MSAccess for reporting (legacy code). We are able to launch MSAccess fine and even work with...
4
by: S. | last post by:
Hi all, I have the requirement that I must pass-by-reference to my function addStudent() and getAge() functions where my getAge() function is within the addStudent() function. I am able to...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.