Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old February 21st, 2006, 02:35 PM
Matt Bob
Guest
 
Posts: n/a
Default MSACCESS 2003 CREATE PROC

I have a vba function im my database to create stored queries in
access. It all works fine except when I start getting into more complex
queries that use aggragate functions.

For example, if I type into a query:

Select tbl1.fieldA, tbl1.fieldB, tbl2.fieldC, sum(tbl2.fieldd) as
sumOfD, iif(sumOfD=0,0,tbl1.fieldB/sumOfD) as ratio FROM tbl1 LEFT JOIN
tbl2 on tbl1.fieldc=tbl2.fieldc WHERE tbl2.fieldE>100 GROUP BY
sum(tbl2.fieldd);

it runs fine, but if I pass the string to this fuction to create the
procedure, it says it needs:
"iif(sumOfD=0,0,tbl1.fieldB/sumOfD)" in the GROUP BY clause. If I try
adding it, it says that it should not be part of the GROUP BY clause.

So.... my question is, is there any way to get by this?

I simply use
CurrentProject.Connection.Execute SQL

to run the SQL, and my SQL string looks like:
CREATE PROC [QueryName] as SelectQuerySQL;

thanks for any help

Matt Bob

  #2  
Old February 22nd, 2006, 10:25 PM
MGFoster
Guest
 
Posts: n/a
Default Re: MSACCESS 2003 CREATE PROC

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The query is incorrect in the GROUP BY clause. Let's try some ANSI 92
syntax instead of JET's syntax (Using an aggregate alias in an
expression):

SELECT T1.fieldA,
T1.fieldB,
T2.fieldC,
IIf(SUM(T2.fieldD)=0,0,T1.fieldB/SUM(T2.fieldD)) as ratio

FROM tbl1 As T1
LEFT JOIN
tbl2 As T2
ON T1.fieldc=T2.fieldc

WHERE T2.fieldE>100

GROUP BY T1.fieldA, T1.fieldB, T2.fieldC

If this fails 'cuz it wants T1.FieldB in the GROUP BY clause, in the
Query's Design column grid, try setting the ratio column's "Total" row
to "Expression."
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQ/zhO4echKqOuFEgEQJcQACg1KZ+tVjD4HsjRHXgEfb+FFlQOCEA n0g7
w9K8+atUA3y6ik+umG81upgU
=5QpP
-----END PGP SIGNATURE-----


Matt Bob wrote:[color=blue]
> I have a vba function im my database to create stored queries in
> access. It all works fine except when I start getting into more complex
> queries that use aggragate functions.
>
> For example, if I type into a query:
>
> Select tbl1.fieldA, tbl1.fieldB, tbl2.fieldC, sum(tbl2.fieldd) as
> sumOfD, iif(sumOfD=0,0,tbl1.fieldB/sumOfD) as ratio FROM tbl1 LEFT JOIN
> tbl2 on tbl1.fieldc=tbl2.fieldc WHERE tbl2.fieldE>100 GROUP BY
> sum(tbl2.fieldd);
>
> it runs fine, but if I pass the string to this fuction to create the
> procedure, it says it needs:
> "iif(sumOfD=0,0,tbl1.fieldB/sumOfD)" in the GROUP BY clause. If I try
> adding it, it says that it should not be part of the GROUP BY clause.
>
> So.... my question is, is there any way to get by this?
>
> I simply use
> CurrentProject.Connection.Execute SQL
>
> to run the SQL, and my SQL string looks like:
> CREATE PROC [QueryName] as SelectQuerySQL;[/color]
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles