[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 1692 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 200 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration
What are your first memories of when Nepal Television Began?
निगुरो थाहा छ ??
ChatSansar.com Naya Nepal Chat
Basnet or Basnyat ??
Sajha has turned into MAGATs nest
NRN card pros and cons?
TPS Re-registration case still pending ..
Do nepalese really need TPS?
कता जादै छ नेपाली समाज ??
Will MAGA really start shooting people?
Democrats are so sure Trump will win
मन भित्र को पत्रै पत्र!
Top 10 Anti-vaxxers Who Got Owned by COVID
I regret not marrying a girl at least for green card. do you think TPS will remain for a long time?
काेराेना सङ्क्रमणबाट बच्न Immunity बढाउन के के खाने ?How to increase immunity against COVID - 19?
TPS Work Permit/How long your took?
Breathe in. Breathe out.
3 most corrupt politicians in the world
Dementia Joe has been selected to become the next President
Nas and The Bokas: Coming to a Night Club near you
Mr. Dipak Gyawali-ji Talk is Cheap. US sends $ 200 million to Nepal every year.
Harvard Nepali Students Association Blame Israel for hamas terrorist attacks
TPS Update : Jajarkot earthquake
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