Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Add filds in access usin SQL code

Posted on 2009-04-09
Medium Priority
182 Views
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,

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
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
• 3
• 2

LVL 120

Expert Comment

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

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

Rey Obrero (Capricorn1) earned 2000 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

ID: 24110655
did the sql work?
0

Author Comment

ID: 24113641
Thank you!
0

## Featured Post

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
###### Suggested Courses
Course of the Month10 days, 3 hours left to enroll