Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2005
    Posts
    61

    cyear between fromyear and toyear (was "urgent Helo In Sql")

    Hi All
    I have DB Called CarSales
    I have two Makes
    Audi
    BMW

    I want To KNow The Qty For Audi And BMW Between 2004 And 2006
    M0 = "Make"
    S0 = "Audi"
    S1 = "BMW"
    fd1 = Text7 ' From Date
    td1 = Text8 ' To Date
    fy1 = year(fd) ' From Year as Integer
    ty1 = year(td) ' To Year as Integer


    I do this Code and it gives Records No = 0 when i Put The Between Years

    rs.Open " SELECT " & M0 & ", Sum(Qty) As Qty, CYear From CarSales Where ( CarSales." & M0 & "= '" & S0 & "' Or CarSales." & M0 & "= '" & S1 & "') Or (CarSales.Cyear between " & fy1 And " & ty1 ) GROUP BY CarSales." & M0 & ", CarSales.CYear ;" NOT WORK COZ OF CYEAR BETWEEN

    rs.Open " SELECT " & M0 & ", Sum(Qty) As Qty, CYear From CarSales Where ( CarSales." & M0 & "= '" & S0 & "' Or CarSales." & M0 & "= '" & S1 & "') GROUP BY CarSales." & M0 & ", CarSales.CYear ;" Worked Correct

    Why? Plz I need YOUR HEL Urgent

    Sami Al Damiri
    Sami Al Damiri ...

  2. #2
    Join Date
    Jan 2005
    Posts
    9
    When you say you want to know quantity for Audi and BMW between 2004 and 2006 im wondering why you are using OR in your query. I would assume you want:

    SELECT Make, Sum(Qty) AS Qty, CYear FROM CarSales WHERE Make IN ('Audi','BMW') AND CYear BETWEEN '2004' AND '2006' GROUP BY Make,CYear;

    Depends on your DB server, some react differently to BETWEEN.
    Also, not sure what datatype you are using for CYear, VARCHAR or DATE?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •