Adding results from count
From: Nitin Rana (Nitin_Rana_at_ibi.Com)
Date: 07/16/04
- Next message: Nitin Rana: "restore from script- exclusive access"
- Previous message: Dan Guzman: "Re: trace 1204"
- In reply to: Zwi2000: "Adding results from count"
- Next in thread: Zwi2000: "Re: Adding results from count"
- Reply: Zwi2000: "Re: Adding results from count"
- Reply: Zwi2000: "Re: Adding results from count"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 15 Jul 2004 18:44:25 -0700
Here is what you need to do: All Set to Go.
All this query is doing here is treating each count(*) as
virtual table and running sum on a virtual table.
SELECT SUM (A) FROM
( Select A FROM (SELECT COUNT(*) FROM users WHERE FirmId
= 1 AND archivedcont = 0 AND I94DateD BETWEEN getdate()
and (getdate()+30)) S (A)
UNION
Select A FROM (SELECT COUNT(*) FROM users WHERE FirmId =
1 AND archivedcont = 0 AND ExpiresonD BETWEEN getdate()
and (getdate()+30) ) U (A) ) T (A)
>-----Original Message-----
>Hi,
>
>This might be an easy one for you. I have an sql which
counts number of
>records, each statement returns one value, and I need to
add the 2 values:
>
>SELECT COUNT(*) AS TOTALI94s
>FROM users
>WHERE FirmId = 1 AND archivedcont = 0 AND
>I94DateD BETWEEN getdate() and (getdate()+30)
>
>
>SELECT COUNT(*) AS TOTALStatus
>FROM users
>WHERE FirmId = 1 AND archivedcont = 0 AND
>ExpiresonD BETWEEN getdate() and (getdate()+30)
>
>
>How can I add them ?
>
>Z
>
>
>.
>
- Next message: Nitin Rana: "restore from script- exclusive access"
- Previous message: Dan Guzman: "Re: trace 1204"
- In reply to: Zwi2000: "Adding results from count"
- Next in thread: Zwi2000: "Re: Adding results from count"
- Reply: Zwi2000: "Re: Adding results from count"
- Reply: Zwi2000: "Re: Adding results from count"
- Messages sorted by: [ date ] [ thread ]