If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > cyear between fromyear and toyear (was "urgent Helo In Sql")

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-01-06, 04:43
Sam76 Sam76 is offline
Registered User
 
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 ...
Reply With Quote
  #2 (permalink)  
Old 03-01-06, 15:53
Whipshock Whipshock is offline
Registered User
 
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?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On