Solved

Add filds in access usin SQL code

Posted on 2009-04-09
5
180 Views
Last Modified: 2012-05-06
I have a table named "Pontage", in this table I have 11 filds: name, H1, H2, H3, H4, H5, WH. In this fild i can write text. I will write data in the first 6 filds. I need a updata query to calculate WH  (please see the example). WH add H1 to H5,

Please help me!
Thank you

example
Name     |   H1   |   H2   |   H3    |   H4   |   H5   ||  WH    
Andy          5         co       L          8         2    ||   15      
Mark           8         8         CM     CM       CM  ||    16                
0
Comment
Question by:Qw M
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 24107390
it is not a common practice to store calculated data to a table.
you can always derive the accurate result using a query, in case any value if any the field change


try this query

SELECT pontage.name, pontage.h1, pontage.h2, pontage.h3, pontage.h4, pontage.h5, IIf(IsNumeric([h1]),CInt([h1]),0)+IIf(IsNumeric([h2]),CInt([h2]),0) +IIf(IsNumeric([h3]),CInt([h3]),0) +IIf(IsNumeric([h4]),CInt([h4]),0) +IIf(IsNumeric([h5]),CInt([h5]),0) AS WH
FROM pontage;
0
 

Author Comment

by:Qw M
ID: 24107869
I have one problem with this code. The query put in the "wh" a round value. For eample if i add H1 to H5 and the rezult is 5.8 then in "wh" i will have 6. How can I make the "wh" to show me the exact number with 2 decimals.

Thank you!  
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 24108063
why didn't you specify in the first place that you have decimal values.


SELECT pontage.name, pontage.h1, pontage.h2, pontage.h3, pontage.h4, pontage.h5, FormatNumber(IIf(IsNumeric([h1]),cdbl([h1]),0)+IIf(IsNumeric([h2]),cdbl([h2]),0)+IIf(IsNumeric([h3]),cdbl([h3]),0)+IIf(IsNumeric([h4]),cdbl([h4]),0)+IIf(IsNumeric([h5]),cdbl([h5]),0),2) AS WH
FROM pontage;
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 24110655
did the sql work?
0
 

Author Comment

by:Qw M
ID: 24113641
Thank you!
0

Featured Post

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question