Results 1 to 2 of 2

Thread: ***Resolved***sql syntax help pls

  1. #1

    Thread Starter
    Hyperactive Member beasty1711's Avatar
    Join Date
    Mar 2001
    Posts
    418

    ***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:
    1. SELECT MAX(Cost) AS 'MAX', MIN(Cost) AS 'MIN', SUM(NumSites) AS sites, COUNT(ID) AS 'COUNT'
    2. FROM tCampaignData
    3. WHERE (ContractorCode = 6) AND (Packagecode = 19) AND (SizeCode = 2) AND (Cost <> 0) AND campcode <> 155
    4.    AND (ID IN
    5.         (SELECT id FROM tcampaigndata WHERE startdate <= '2002-Dec-23' AND enddate >= '2002-Dec-23'))
    6.    or(ID IN
    7.         (SELECT id FROM tcampaigndata WHERE startdate >= '2002-Dec-23' AND enddate <= '2003-Mar-30'))
    8.    or(ID IN
    9.         (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

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    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
  •  



Click Here to Expand Forum to Full Width