Solved

Add filds in access usin SQL code

Posted on 2009-04-09
5
172 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 119

Expert Comment

by:Rey Obrero
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 119

Accepted Solution

by:
Rey Obrero 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 119

Expert Comment

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

Author Comment

by:Qw M
ID: 24113641
Thank you!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now