Solved

Add filds in access usin SQL code

Posted on 2009-04-09
5
177 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
  • 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to prevent deleting SQL tables thru FE Application? 20 78
ADODB problem 20 35
UK Date format in MS Access 4 19
SQL Recursion schedule 13 13
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

792 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