[Show all top banners]

Nepalover
Replies to this thread:

More by Nepalover
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 MS Access Question - technical
[VIEWED 2152 TIMES]
SAVE! for ease of future access.
Posted on 09-14-06 1:58 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Guys,
I have a little complicated access question, I would appreciate if any of you can help me. Here is the scenario:
I have a query that is pulling different boxes from the table, let say the boxes are A, B, C, D and E. In the query, I need to perform some calculation, however, those calculations are not the same for all the boxes. For box A - the calculation should be A/2, for B - calculation should be B*2, for C - C*25 etc. Is this even possible in access?

Thanks in advance for your help!
 
Posted on 09-14-06 2:54 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

If you have a table that looks something like following:

TABLE Boxes

A B C
2 2 1
4 9 2
5 2 6
6 1 1

Then, you could do something like this:

SELECT A/2 as Calc1, B*2 as Calc2, C - (C*25) as Calc3 FROM Boxes;

And if you don't want any titles, then remove "as CalcXXX" part!
 
Posted on 09-15-06 8:30 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Nepali kancha,
My table looks like following

Apple 5
Orange 6
Mangoes 20
Grapes 100

(Let say, we are cutting apples in 2 pieces, orange in 4 pieces, Mangoes in 3 pieces and divide grapes by 10)

If my field has apple then 5*2
If my field has Orange then 6*4
If my field has Mangoes then 20*3
If my field has grape then 100/10

Thanks for your help!
 
Posted on 09-15-06 11:03 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

I'm pretty positive that Access SQL is pretty limited and will not allow you to use If-Then or other programming languages. The only way I can think of accomplishing what you want is as follows:

Setup two tables: Fruits & FruitsDistribution

I have attached "Fruits" table with this post. Setup "FruitsDistribution" the same way as "Fruits" but leave it empty. Create a form and add a button called "cmdCalculate". Copy the following code to cmdCalculate:

Set db = CurrentDb

strQry = "SELECT * FROM Fruits"
Set rec = db.OpenRecordset(strQry, dbOpenDynaset)

rec.MoveFirst

Do Until rec.EOF

If rec.Fields(0) = "Apple" Then
strInsert = "INSERT INTO FruitsDistribution VALUES ('" & rec.Fields(0) & "', " & rec.Fields(1) * 2 & ")"
db.Execute (strInsert)
End If
If rec.Fields(0) = "Oranges" Then
strInsert = "INSERT INTO FruitsDistribution VALUES ('" & rec.Fields(0) & "', " & rec.Fields(1) * 4 & ")"
db.Execute (strInsert)
End If
If rec.Fields(0) = "Mangoes" Then
strInsert = "INSERT INTO FruitsDistribution VALUES ('" & rec.Fields(0) & "', " & rec.Fields(1) * 3 & ")"
db.Execute (strInsert)
End If
If rec.Fields(0) = "Grapes" Then
strInsert = "INSERT INTO FruitsDistribution VALUES ('" & rec.Fields(0) & "', " & rec.Fields(1) / 10 & ")"
db.Execute (strInsert)
End If

rec.MoveNext

Loop

There might be easier way, but, I'm just out of ideas right now.

 
Posted on 09-15-06 11:05 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

And then, you can just query FruitsDistribution.
 
Posted on 09-15-06 11:29 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Thanks Nepali Kancha!
 
Posted on 09-15-06 11:38 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

You are welcome! :)
 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 90 days
Recommended Popular Threads Controvertial Threads
TPS To F-1 COS
TPS to F1 Status.
Nepal TPS has been Extended !!!
Got my F1 reinstatement approved within 3 months(was out of F1 for almost 2 years)
#MAGA#FAFO is delicious
TPS of Nepal to be automatically extended for 6 months based on South Sudan decision
Democrat lies revealed
Nepal TPS decision
Has anyone here successfully reinstated to F-1 status after a year-long gap following a drop from F-1?
US citizen Petitioning my wife who was out of status when she was in H1B. What to do ?
TPS Sakiyo Tara Case is in Court.
Supreme Court allows Trump to end TPS for Venezuelans
Genuine Question.... Why so many folks still in TPS after 10 years. Is the statistics wrong?
Any input on remote jobs(IT related or Sales or Marketing)?
Nepal Likely to Get 60-Day TPS Notice
मुद्दा हाल्छन होला र ?
TPS cancel bho bhane k garne?
नेपाल मा B. sc गरियो यहाँ फेरी ७० -८० क्रेडिट पढ्नु पर्ने भो
EAD HELP NEEDED URGENTLY!
Don’t Just Read—Join the Conversation
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters