[Show all top banners]

Nepalover
Replies to this thread:

More by Nepalover
What people are reading
Subscribers
:: Subscribe
Back to: Computer/IT Refresh page to view new replies
 Question for MS ACCESS GURU

[Please view other pages to see the rest of the postings. Total posts: 48]
PAGE: <<  1 2 3 NEXT PAGE
[VIEWED 15475 TIMES]
SAVE! for ease of future access.
The postings in this thread span 3 pages, View Last 20 replies.
Posted on 09-14-06 2:05 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-15-06 11:01 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

One more question, when I use the SQL query:

SELECT Fruit, Num, IIf([Fruit]='Apple',Num*3) AS AppleSlice, IIf([Fruit]='Orange',Num/2) AS OrangeSlice, IIf([Fruit]='Banana',Num+3) AS BananaSlice
FROM Table1;

The calculated column are different where the results are stored, if I try to use the following query, it tells me the duplicate field.

SELECT Fruit, Num, IIf([Fruit]='Apple',Num*3) AS Fruitsqty, IIf([Fruit]='Orange',Num/2) AS Fruitsqty, IIf([Fruit]='Banana',Num+3) AS Fruitsqty
FROM Table1;

I need to put all of the calculated numbers in one column, it it possible using the CASE WHEN query? I tried it but I'm getting the syntax errors....
 
Posted on 09-15-06 11:15 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Nepalover,

The CASE WHEN seems to be for SQL server, for Access use the Switch statement like following:

SELECT fruit, N,
Switch(
fruit='apple',N*2,
fruit='orange',N/3
) AS calculatedcolumn
FROM yourtable;

you can use multiple fruit = 'xxx', and calculations on the above statement to get your result
 
Posted on 09-15-06 11:38 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Getting Compile error while using the above SQL statement.
 
Posted on 09-15-06 11:45 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Make sure the field names match ie. fruit and N
 
Posted on 09-15-06 11:48 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Also make sure that your field N has datatype of 'number'
 
Posted on 09-15-06 2:39 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Nepalover,
I hope you solved your problem. Bhusan gave you good suggestions. Yes, use switch statement instead of if/then/else to produce a single column result. When you get syntax error, check for any missing quotes as well.
 
Posted on 09-18-06 10:51 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Here is the SQL Switch statement I'm using:

SELECT Process, TransactionsCompleted,
Switch(
Process ='SPRD100',TransactionsCompleted*2,
Process ='SPRD500',TransactionsCompleted*3,
Process ='SPRD750',TransactionsCompleted*5,
) AS calculatedcolumn
FROM TBLSystemTransactions;

(Process=Fruit, TransactionsCompleted = N)

However, I'm still getting the compile error. Can you check the statement and see any errors?

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

there is an extra comma after

Process ='SPRD750',TransactionsCompleted*5,

try to remove that last comma
 
Posted on 09-18-06 11:05 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Sorry, that was a typo... I ran it after getting rid of that comma... still getting the compile error.

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

What are the datatypes of Process and TransactionsCompleted fields?
 
Posted on 09-18-06 12:53 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Nepal lover, my guess is your data type must be screwed up! Here is what you should do:

 
Posted on 09-18-06 12:54 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Original table

 
Posted on 09-18-06 12:55 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 
 
Posted on 09-18-06 12:55 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 
 
Posted on 09-18-06 12:56 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Sorry for not resizing the big images.
 
Posted on 09-18-06 1:37 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Batuwa,
That is exactly what I have. I have Transactionscompleted as a numeric (number) field. I have the SQL typed in exactly as you have.
 
Posted on 09-18-06 1:43 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Either your install of Access is faulty, try to reinstall access , or perhaps your computer doesn't have enuff juice for the query, try it on a different computer.
 
Posted on 09-18-06 1:47 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

One more thing, I have 4 fields in the table:

UserID Process TransactionsCompleted Date

Would that be a problem that I'm not including the 2 other column names in the SQL (UserID and Date)?
 
Posted on 09-18-06 1:49 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

First of all, check your code again. Carefully check for any missing or unnecessary commas or quotes. Sometimes you need second set of eyes. Try in some other computers than yours if you're in lab.
 
Posted on 09-18-06 1:51 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

can u post the screen shots of your orignal table and SQL?
 



PAGE: <<  1 2 3 NEXT PAGE
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 30 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration case still pending ..
ढ्याउ गर्दा दसैँको खसी गनाउच
To Sajha admin
From Trump “I will revoke TPS, and deport them back to their country.”
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