473,411 Members | 2,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Query Question

I am trying to create a query for my sampling size table and I can’t get the right expression i.e. Lot Size 1 to 50 = 5 and so on… I tried the AQL: IIf([Test].[Lot Size]<=50,"5") and I can’t pass the beyond this expression.

Lot Size ----- Sample Size
1-50 ---------------- 5
51-90 --------------- 7
91-150 ------------- 11
151-280 ----------- 13
281-500 ---------- 16
501-1200 --------- 19
1201-3200 --------- 23
3201-10000 ---------- 29
10001-35000 ------- 35
35001- Over -----40

Thanks
Jun 26 '08 #1
5 1153
ADezii
8,834 Expert 8TB
Assuming you have a Table named tblLotSize consisting of a single Field named [Lot Size] {LONG}, then the following Query and associated Function shouold return the desired results for you as indicated by the Sample Data and Output:
  1. Query SQL:
    Expand|Select|Wrap|Line Numbers
    1. SELECT tblLotSize.[Lot Size], fReturnSampleSize([Lot Size]) AS [Sample Size]
    2. FROM tblLotSize;
  2. Function utilized in the Query:
    Expand|Select|Wrap|Line Numbers
    1. Public Function fReturnSampleSize(lngLotSize As Long) As Variant
    2. Select Case lngLotSize
    3.   Case Is >= 35001
    4.     fReturnSampleSize = 40
    5.   Case Is >= 10001
    6.     fReturnSampleSize = 35
    7.   Case Is >= 3201
    8.     fReturnSampleSize = 29
    9.   Case Is >= 1201
    10.     fReturnSampleSize = 23
    11.   Case Is >= 501
    12.     fReturnSampleSize = 19
    13.   Case Is >= 281
    14.     fReturnSampleSize = 16
    15.   Case Is >= 151
    16.     fReturnSampleSize = 13
    17.   Case Is >= 91
    18.     fReturnSampleSize = 11
    19.   Case Is >= 51
    20.     fReturnSampleSize = 7
    21.   Case Is >= 1
    22.     fReturnSampleSize = 5
    23.   Case Else
    24.     fReturnSampleSize = Null
    25. End Select
    26. End Function
  3. Sample Data in tblLotSize:
    Expand|Select|Wrap|Line Numbers
    1. Lot Size
    2. 1
    3. 50
    4. 51
    5. 90
    6. 91
    7. 150
    8. 151
    9. 280
    10. 281
    11. 500
    12. 501
    13. 1200
    14. 1201
    15. 3200
    16. 3201
    17. 10000
    18. 10001
    19. 35000
    20. 35001
    21. 692
    22. 89765
    23. -13
  4. OUTPUT of Query:
    Expand|Select|Wrap|Line Numbers
    1. Lot Size    Sample Size
    2. 1                 5
    3. 50                 5
    4. 51                 7
    5. 90                 7
    6. 91                11
    7. 150                11
    8. 151                13
    9. 280                13
    10. 281                16
    11. 500                16
    12. 501                19
    13. 1200            19
    14. 1201            23
    15. 3200            23
    16. 3201            29
    17. 10000            29
    18. 10001            35
    19. 35000            35
    20. 35001            40
    21. 692                19
    22. 89765            40
    23. -13    
Jun 27 '08 #2
Where do i put the Query SQL and the Function... Sorry I'm a newbie and still learning...
Thanks again.
J

Assuming you have a Table named tblLotSize consisting of a single Field named [Lot Size] {LONG}, then the following Query and associated Function shouold return the desired results for you as indicated by the Sample Data and Output:
  1. Query SQL:
    Expand|Select|Wrap|Line Numbers
    1. SELECT tblLotSize.[Lot Size], fReturnSampleSize([Lot Size]) AS [Sample Size]
    2. FROM tblLotSize;
  2. Function utilized in the Query:
    Expand|Select|Wrap|Line Numbers
    1. Public Function fReturnSampleSize(lngLotSize As Long) As Variant
    2. Select Case lngLotSize
    3.   Case Is >= 35001
    4.     fReturnSampleSize = 40
    5.   Case Is >= 10001
    6.     fReturnSampleSize = 35
    7.   Case Is >= 3201
    8.     fReturnSampleSize = 29
    9.   Case Is >= 1201
    10.     fReturnSampleSize = 23
    11.   Case Is >= 501
    12.     fReturnSampleSize = 19
    13.   Case Is >= 281
    14.     fReturnSampleSize = 16
    15.   Case Is >= 151
    16.     fReturnSampleSize = 13
    17.   Case Is >= 91
    18.     fReturnSampleSize = 11
    19.   Case Is >= 51
    20.     fReturnSampleSize = 7
    21.   Case Is >= 1
    22.     fReturnSampleSize = 5
    23.   Case Else
    24.     fReturnSampleSize = Null
    25. End Select
    26. End Function
  3. Sample Data in tblLotSize:
    Expand|Select|Wrap|Line Numbers
    1. Lot Size
    2. 1
    3. 50
    4. 51
    5. 90
    6. 91
    7. 150
    8. 151
    9. 280
    10. 281
    11. 500
    12. 501
    13. 1200
    14. 1201
    15. 3200
    16. 3201
    17. 10000
    18. 10001
    19. 35000
    20. 35001
    21. 692
    22. 89765
    23. -13
  4. OUTPUT of Query:
    Expand|Select|Wrap|Line Numbers
    1. Lot Size    Sample Size
    2. 1                 5
    3. 50                 5
    4. 51                 7
    5. 90                 7
    6. 91                11
    7. 150                11
    8. 151                13
    9. 280                13
    10. 281                16
    11. 500                16
    12. 501                19
    13. 1200            19
    14. 1201            23
    15. 3200            23
    16. 3201            29
    17. 10000            29
    18. 10001            35
    19. 35000            35
    20. 35001            40
    21. 692                19
    22. 89765            40
    23. -13    
Jun 30 '08 #3
ADezii
8,834 Expert 8TB
Where do i put the Query SQL and the Function... Sorry I'm a newbie and still learning...
Thanks again.
J
Download the Attachment which consists of the Test Database and only three Objects: a Table, Query, and Module. You should be able to get a very clear picture of what is going on now.
Jun 30 '08 #4
Thank you very much...Now I got it...

Download the Attachment which consists of the Test Database and only three Objects: a Table, Query, and Module. You should be able to get a very clear picture of what is going on now.
Jun 30 '08 #5
ADezii
8,834 Expert 8TB
You are quite welcome, sometimes a picture is worth a thousand words (LOL).
Jun 30 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: majsen | last post by:
Hi, I have problem running this query. It will time out for me... My database are small just about 200 members. I have a site for swaping appartments (rental). my query should look for match in...
8
by: Együd Csaba | last post by:
Hi All, how can I improve the query performance in the following situation: I have a big (4.5+ million rows) table. One query takes approx. 9 sec to finish resulting ~10000 rows. But if I run...
3
by: John Ortt | last post by:
> I have a table of dates in ascending order but with varying intervals. I > would like to create a query to pull out the date (in field 1) and then pull > the date from the subsequent record...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
7
by: serge | last post by:
How can I run a single SP by asking multiple sales question either by using the logical operator AND for all the questions; or using the logical operator OR for all the questions. So it's always...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
2
by: mmitchell_houston | last post by:
I'm working on a .NET project and I need a single query to return a result set from three related tables in Access 2003, and I'm having trouble getting the results I want. The details: ...
22
by: Stan | last post by:
I am working with Access 2003 on a computer running XP. I am new at using Access. I have a Db with a date field stored as mm/dd/yyyy. I need a Query that will prompt for the month, ie. 6 for...
3
by: Richard Hollenbeck | last post by:
I am very sorry about the (almost) re-post, but you will see that my first question wasn't very clear; I have another question I posted this morning called, "in DAO: Run time error 3061 Too few...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.