dbTalk Databases Forums  

sum two subqueries

comp.databases.ms-access comp.databases.ms-access


Discuss sum two subqueries in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
remigio
 
Posts: n/a

Default sum two subqueries - 07-22-2010 , 03:54 AM






Hi,
I'm trying to sum two sub-queries with this code:

SELECT Count(*) AS Attivi
FROM adi
WHERE (((adi.pratica_2010) Is Not Null) And ((adi.stato_pratica) Is
Null) And ((adi.data_attivazione)<=Forms!interrogazioni_ADI! fine))
+
select count(*) from adi where ((stato_pratica is not null) and
(data_variazione <=[Forms]![interrogazioni_ADI]![fine] ) and
(data_variazione >=[Forms]![interrogazioni_ADI]![inizio]));

but I don't know the right sintax.
Can you help me, please?
Thanks

Reply With Quote
  #2  
Old   
Douglas J. Steele
 
Posts: n/a

Default Re: sum two subqueries - 07-22-2010 , 05:40 AM






Rather than using Count, try using an IIf statement that returns 1 if the
condition is met and 0 if it isn't, and Sum that calculated field:

SELECT Sum(IIf(IsNull([practica_2010]) = False AND IsNull([stato_practica])
= True AND [data_attivazione]<=Forms!interrogazioni_ADI!fine), 1, 0) AS
Attivi, Sum(IsNull([stato_practica]) = False AND ([data_variazione] BETWEEN
[Forms]![interrogazioni_ADI]![inizio] AND
[Forms]![interrogazioni_ADI]![fine]), 1, 0)
FROM adi



--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
Co-author: Access 2010 Solutions, published by Wiley
(no e-mails, please!)

"remigio" <linoreale (AT) gmail (DOT) com> wrote

Quote:
Hi,
I'm trying to sum two sub-queries with this code:

SELECT Count(*) AS Attivi
FROM adi
WHERE (((adi.pratica_2010) Is Not Null) And ((adi.stato_pratica) Is
Null) And ((adi.data_attivazione)<=Forms!interrogazioni_ADI! fine))
+
select count(*) from adi where ((stato_pratica is not null) and
(data_variazione <=[Forms]![interrogazioni_ADI]![fine] ) and
(data_variazione >=[Forms]![interrogazioni_ADI]![inizio]));

but I don't know the right sintax.
Can you help me, please?
Thanks

Reply With Quote
  #3  
Old   
remigio
 
Posts: n/a

Default Re: sum two subqueries - 07-22-2010 , 08:42 AM



On 22 Lug, 12:40, "Douglas J. Steele"
<NOSPAM_djsteele (AT) NOSPAM_gmail (DOT) com> wrote:
Quote:
Rather than using Count, try using an IIf statement that returns 1 if the
condition is met and 0 if it isn't, and Sum that calculated field:

SELECT Sum(IIf(IsNull([practica_2010]) = False AND IsNull([stato_practica])
= True AND [data_attivazione]<=Forms!interrogazioni_ADI!fine), 1, 0) AS
Attivi, Sum(IsNull([stato_practica]) = False AND ([data_variazione] BETWEEN
[Forms]![interrogazioni_ADI]![inizio] AND
[Forms]![interrogazioni_ADI]![fine]), 1, 0)
FROM adi

--
Doug Steele, Microsoft Access MVPhttp://www.AccessMVP.com/DJSteele
Co-author: Access 2010 Solutions, published by Wiley
(no e-mails, please!)

"remigio" <linore... (AT) gmail (DOT) com> wrote in message

news:bdcdf756-4f53-4e60-97c5-06e33060e2fc (AT) e5g2000yqn (DOT) googlegroups.com...

Hi,
I'm trying to sum two sub-queries with this code:

SELECT Count(*) AS Attivi
FROM adi
WHERE (((adi.pratica_2010) Is Not Null) And ((adi.stato_pratica) Is
Null) And ((adi.data_attivazione)<=Forms!interrogazioni_ADI! fine))
+
select count(*) from adi where ((stato_pratica is not null) and
(data_variazione <=[Forms]![interrogazioni_ADI]![fine] ) and
(data_variazione >=[Forms]![interrogazioni_ADI]![inizio]));

but I don't know the right sintax.
Can you help me, please?
Thanks
This code gets an error:
"wrong number of arguments used with function in query"
Is it possible to sum queries each other?

Reply With Quote
  #4  
Old   
Douglas J. Steele
 
Posts: n/a

Default Re: sum two subqueries - 07-22-2010 , 11:11 AM



Sorry, my fault.

SELECT Sum(IIf(IsNull([practica_2010]) = False AND IsNull([stato_practica])
= True AND [data_attivazione]<=Forms!interrogazioni_ADI!fine), 1, 0)) AS
Attivi, Sum(IIf(IsNull([stato_practica]) = False AND ([data_variazione]
BETWEEN
[Forms]![interrogazioni_ADI]![inizio] AND
[Forms]![interrogazioni_ADI]![fine])), 1, 0))
FROM adi

Why run two queries when one will do?

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
Co-author: Access 2010 Solutions, published by Wiley
(no e-mails, please!)

"remigio" <linoreale (AT) gmail (DOT) com> wrote

Quote:
On 22 Lug, 12:40, "Douglas J. Steele"
NOSPAM_djsteele (AT) NOSPAM_gmail (DOT) com> wrote:
Rather than using Count, try using an IIf statement that returns 1 if the
condition is met and 0 if it isn't, and Sum that calculated field:

SELECT Sum(IIf(IsNull([practica_2010]) = False AND
IsNull([stato_practica])
= True AND [data_attivazione]<=Forms!interrogazioni_ADI!fine), 1, 0) AS
Attivi, Sum(IsNull([stato_practica]) = False AND ([data_variazione]
BETWEEN
[Forms]![interrogazioni_ADI]![inizio] AND
[Forms]![interrogazioni_ADI]![fine]), 1, 0)
FROM adi

--
Doug Steele, Microsoft Access MVPhttp://www.AccessMVP.com/DJSteele
Co-author: Access 2010 Solutions, published by Wiley
(no e-mails, please!)

"remigio" <linore... (AT) gmail (DOT) com> wrote in message

news:bdcdf756-4f53-4e60-97c5-06e33060e2fc (AT) e5g2000yqn (DOT) googlegroups.com...

Hi,
I'm trying to sum two sub-queries with this code:

SELECT Count(*) AS Attivi
FROM adi
WHERE (((adi.pratica_2010) Is Not Null) And ((adi.stato_pratica) Is
Null) And ((adi.data_attivazione)<=Forms!interrogazioni_ADI! fine))
+
select count(*) from adi where ((stato_pratica is not null) and
(data_variazione <=[Forms]![interrogazioni_ADI]![fine] ) and
(data_variazione >=[Forms]![interrogazioni_ADI]![inizio]));

but I don't know the right sintax.
Can you help me, please?
Thanks

This code gets an error:
"wrong number of arguments used with function in query"
Is it possible to sum queries each other?

Reply With Quote
  #5  
Old   
remigio
 
Posts: n/a

Default Re: sum two subqueries - 07-24-2010 , 01:08 AM



On 22 Lug, 18:11, "Douglas J. Steele"
<NOSPAM_djsteele (AT) NOSPAM_gmail (DOT) com> wrote:
Quote:
Sorry, my fault.

SELECT Sum(IIf(IsNull([practica_2010]) = False AND IsNull([stato_practica])
= True AND [data_attivazione]<=Forms!interrogazioni_ADI!fine), 1, 0)) AS
Attivi, Sum(IIf(IsNull([stato_practica]) = False AND ([data_variazione]
BETWEEN
[Forms]![interrogazioni_ADI]![inizio] AND
[Forms]![interrogazioni_ADI]![fine])), 1, 0))
FROM adi

Why run two queries when one will do?

--
Doug Steele, Microsoft Access MVPhttp://www.AccessMVP.com/DJSteele
Co-author: Access 2010 Solutions, published by Wiley
(no e-mails, please!)

"remigio" <linore... (AT) gmail (DOT) com> wrote in message

news:533d3a18-5041-4d24-afcf-fb3deb78d1cb (AT) k19g2000yqc (DOT) googlegroups.com...

On 22 Lug, 12:40, "Douglas J. Steele"
NOSPAM_djsteele (AT) NOSPAM_gmail (DOT) com> wrote:
Rather than using Count, try using an IIf statement that returns 1 if the
condition is met and 0 if it isn't, and Sum that calculated field:

SELECT Sum(IIf(IsNull([practica_2010]) = False AND
IsNull([stato_practica])
= True AND [data_attivazione]<=Forms!interrogazioni_ADI!fine), 1, 0) AS
Attivi, Sum(IsNull([stato_practica]) = False AND ([data_variazione]
BETWEEN
[Forms]![interrogazioni_ADI]![inizio] AND
[Forms]![interrogazioni_ADI]![fine]), 1, 0)
FROM adi

--
Doug Steele, Microsoft Access MVPhttp://www.AccessMVP.com/DJSteele
Co-author: Access 2010 Solutions, published by Wiley
(no e-mails, please!)

"remigio" <linore... (AT) gmail (DOT) com> wrote in message

news:bdcdf756-4f53-4e60-97c5-06e33060e2fc (AT) e5g2000yqn (DOT) googlegroups.com...

Hi,
I'm trying to sum two sub-queries with this code:

SELECT Count(*) AS Attivi
FROM adi
WHERE (((adi.pratica_2010) Is Not Null) And ((adi.stato_pratica) Is
Null) And ((adi.data_attivazione)<=Forms!interrogazioni_ADI! fine))
+
select count(*) from adi where ((stato_pratica is not null) and
(data_variazione <=[Forms]![interrogazioni_ADI]![fine] ) and
(data_variazione >=[Forms]![interrogazioni_ADI]![inizio]));

but I don't know the right sintax.
Can you help me, please?
Thanks

This code gets an error:
"wrong number of arguments used with function in query"
Is it possible to sum queries each other?
Tnx!

Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.