|
-
Feb 17th, 2004, 07:47 AM
#1
Thread Starter
Hyperactive Member
***Resolved***sql syntax help pls
I'm trying to do some SQL to extract some data
I need to filter the data like so:
B>= A & C>=A
OR
B>=A & C<=D
OR
B<=D & C>=D
Soo far I have...
VB Code:
SELECT MAX(Cost) AS 'MAX', MIN(Cost) AS 'MIN', SUM(NumSites) AS sites, COUNT(ID) AS 'COUNT'
FROM tCampaignData
WHERE (ContractorCode = 6) AND (Packagecode = 19) AND (SizeCode = 2) AND (Cost <> 0) AND campcode <> 155
AND (ID IN
(SELECT id FROM tcampaigndata WHERE startdate <= '2002-Dec-23' AND enddate >= '2002-Dec-23'))
or(ID IN
(SELECT id FROM tcampaigndata WHERE startdate >= '2002-Dec-23' AND enddate <= '2003-Mar-30'))
or(ID IN
(SELECT id FROM tcampaigndata WHERE startdate <= '2003-Mar-30' AND enddate >= '2003-Mar-30'))
Any ideas where i am going wrong and/ or if its possible to do what i need??
Last edited by beasty1711; Feb 18th, 2004 at 02:51 AM.
"...They even have the internet on computers..." :- Homer Simpson
"Second Place is First Looser" :- No Fear
-
Feb 17th, 2004, 11:33 AM
#2
What database? Why the subqueries? Just add the criterias to your where clause. If this is an Access database then date fields must be surrounded with # not '.
Code:
SELECT MAX(Cost) AS 'MAX', MIN(Cost) AS 'MIN', SUM(NumSites) AS sites, COUNT(ID) AS 'COUNT'
FROM tCampaignData
WHERE (ContractorCode = 6) AND (Packagecode = 19) AND (SizeCode = 2) AND (Cost <> 0) AND campcode <> 155
AND ( (startdate <= '2002-Dec-23' AND enddate >= '2002-Dec-23') OR
(startdate >= '2002-Dec-23' AND enddate <= '2003-Mar-30') OR
(startdate <= '2003-Mar-30' AND enddate >= '2003-Mar-30')
)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|