[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 2154 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 365 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration case still pending ..
ChatSansar.com Naya Nepal Chat
सालीको चाक
Conservative discussions
tesla stock OMG !!
Looking for girl
Who is hottest nepali female?
TPS for Nepal likely to extend next week
Anybody gotten the TPS EAD extension alert notice (i797) thing? online or via post?
Toilet paper or water?
I hope all the fake Nepali refugee get deported
Those who are in TPS, what’s your backup plan?
ढ्याउ गर्दा दसैँको खसी गनाउच
TPS To F-1 COS
Sajha Poll: Who is your favorite Nepali actress?
Mamta kafle bhatt is still missing
Problems of Nepalese students in US
Homeland Security revokes temporary status for 532,000 Cubans, Haitians, Nicaraguans and Venezuelans
Venezuela TPS lawuit
Embassy of Nepal might be able to help extend TPS for Nepal
Looking for girl
Who is hottest nepali female?
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