473,408 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

summing a text field

I have a text field called ActualLaborHours. I need to be able to sum the labor hours in a query can someone help me do this or direct me in the right direction?
Oct 29 '18 #1
5 1261
NeoPa
32,556 Expert Mod 16PB
You say your field [ActualLaborHours] is actually a Text field but don't explain why this is so. It seems a spectacularly obvious design error. Obviously, we sometimes have to deal with design problems when we have received them from other people, who themselves may be idiots.

So, let's answer the question. The first and most obvious thing to say is that, if it's within your power, get the design changed. Make it a numeric field and lose the complication.

If that isn't possible then you will need to use Sum() of Val() or similar. With very little, to no, background explanation we can only know you need a numeric result. That would be done with a field in your SQL similar to :
Expand|Select|Wrap|Line Numbers
  1. SELECT ...
  2.      , Sum(Val([ActualLaborHours])) AS [SumLaborHours]
  3. FROM   [...]
Oct 29 '18 #2
That didnt work I need to sum ActualLabor hours. When I copy the records in excel i am able to convert the text to a number and i get the correct sum of that fiels but I need to be able to do that in access. I have attached the query.
Expand|Select|Wrap|Line Numbers
  1. SELECT [Maximo Report].WorkOrder, ([ActualStartDate]-[ReportedDate]) AS Expr1, [Maximo Report].[Estimated Labor Hours], [Maximo Report].WorkType, [Maximo Report].ActualStartDate, [Maximo Report].ActualLaborHours
  2. FROM [Maximo Report]
  3. WHERE (((([ActualStartDate]-[ReportedDate]))<3.5) AND (([Maximo Report].[Estimated Labor Hours])="00:00") AND (([Maximo Report].WorkType)="CM" Or ([Maximo Report].WorkType)="EM" Or ([Maximo Report].WorkType)="MMNRO" Or ([Maximo Report].WorkType)="MMROI" Or ([Maximo Report].WorkType)="PMCM" Or ([Maximo Report].WorkType)="PMINS" Or ([Maximo Report].WorkType)="PMOR" Or ([Maximo Report].WorkType)="PMPDM" Or ([Maximo Report].WorkType)="PMREG" Or ([Maximo Report].WorkType)="PMRT") AND (([Maximo Report].ActualStartDate)>=DateAdd("h",-1,[Enter the Start Date]) And ([Maximo Report].ActualStartDate)<DateAdd("h",23,[Enter the End Date]))) OR ((([Maximo Report].WorkType)="EM") AND (([Maximo Report].ActualStartDate)>=DateAdd("h",-1,[Enter the Start Date]) And ([Maximo Report].ActualStartDate)<DateAdd("h",23,[Enter the End Date])));
I need to Add the Total ActualLaborHours.
Oct 30 '18 #3
NeoPa
32,556 Expert Mod 16PB
Jeannier1975:
That didnt work I need to sum ActualLabor hours.
What didn't? What did you try and where exactly did it go wrong?

If we're to help you then we need a little more involvement from you than "That didn't work".

As I mentioned in my first reply, you share very little information. Basic obvious stuff like what the circumstances are and what you're trying to do - even in general terms.

Summing is a fine concept, but it has very different results depending on what grouping you're using. Across the recordset as a whole is a very different result from just those within a particular group. I've seen nothing as yet to tell me what it is you're trying to achieve.

The solution provided earlier does work, of course, but you have to use it in accordance with whatever it is you expect. Sum() within a single record simply gives you the same value back. Even then you'd need to specify the grouping in the GROUP BY clause in order for it to work for you.

The other major problem is that whenever you do any aggregating within a query then the query expects everything to be aggregated, obviously. It couldn't possibly give you the aggregated results unless there is some understanding of grouping, and if there is such an understanding then individual values make no sense. What would be the name value of a grouped set of records encompassing multiple records each with a different name?

There are techniques that allow us to get around such restrictions. What I said before is still true but we can nevertheless link to separate queries that allow us to find an aggregated total that is linked into each individual record. That would have to be created and made available in a separate section of course.

As I say possible, but we'd need a far clearer explanation of what you're actually after if we're even to make a start in that direction. Hopefully it won't be necessary but from your posted SQL I would guess that's where we're heading. Not enough to be sure but the indications are there.
Nov 1 '18 #4
PhilOfWalton
1,430 Expert 1GB
This is just a repeat of https://bytes.com/topic/access/answe...sum-time-field

that I thought I had answered but got no response.

If ActualLaborHours is a text field coming from Excel, try using
Expand|Select|Wrap|Line Numbers
  1. CDate(ActualLaborHours)
instead.

Depending if you are using UK dates (DD/MM/YYYY) or US Dates (MM/DD/YYYY) you may get different answers

Phil
Nov 1 '18 #5
NeoPa
32,556 Expert Mod 16PB
Technically it's different as the other isn't described as being held in text format. That may simply be the lack of attention and effort on behalf of the OP of course. Signs are not good as they seem unwilling or unable to do put in the basic level of effort to explain their own problem properly. So far at least. Maybe they're just struggling to understand. DB work can seem particularly complicated to a lot of people. We'll see what they come up with and hopefully we'll have a full and clear question we can simply provide an answer to.
Nov 2 '18 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Michael Walton | last post by:
I am trying to write some code that inserts or updates a text field in my SQL Server 2000 database. The SQL statement is created using a submit from a form, and the text is coming from a...
7
by: Rick Caborn | last post by:
Does anyone know of a way to execute sql code from a dynamically built text field? Before beginning, let me state that I know this db architecture is built solely for frustration and I hope to...
2
by: ehm | last post by:
I am working on creating an editable grid (for use in adding, deleting, and editing rows back to an Oracle database). I have a JSP that posts back to a servlet, which in turns posts to a WebLogic...
3
by: Roy Adams | last post by:
Hi I'm reposting this question because for some reason can't post follow up question to this thread. What I'm trying to do is put the value and text from a a select in to a text field and to a...
2
by: NewBob | last post by:
Since Access automatically highlights all of the text in a text control (I use it to hold data from a memo field) when the control is activated, I've added the following code to put the cursor at...
2
by: steveprevost | last post by:
I have a text field that contains mostly numbers, but the rows without a value have a blank in them. I need to sum on this row, but I get a conversion error. I've tried using various functions...
3
by: dugald.morrow | last post by:
I have some javascript that updates the text in a text field after certain actions take place such as clicking a checkbox. The javascript works fine in Safari and Firefox, but in IE, the text in...
2
by: John Kotuby | last post by:
Hi all, Maybe this belongs in the Full Text group but I am writing an ASP.NET application with a SQL Server 2005 backend, so I am posing the question here. I have been using fulltext search...
1
DebadattaMishra
by: DebadattaMishra | last post by:
Introduction In case of rich applications, you must have observed that a text field behaves like a dynamic combo box. When the user enters some characters in the text field, a popup will come up...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.