I have a table with some fields. break_mon, lunch_mon, dinner_mon, ent_mon,
break_tue, lunch_tue, dinner_tue, ent_tue, .....etc
I want to output the sum of the four monday columns as well as the sum of
the four tuesday columns.
I did this with
SELECT break_mon+lunch_mon+dinner_mon+ent_mon AS mon_tot,
break_tue+lunch_tue+dinner_tue+ent_tue AS tue_tot
FROM expense_report
I now want to add mon_tot and tue_tot AS total, but SQL is telling me that
it can not find mon_tot. Is there a way to do this? Thanks!
Darren
MCP 4 20676
"Scrappy" <ce*****@lan-specialist.com> wrote in message
news:YW********************@twister.nyroc.rr.com.. . I have a table with some fields. break_mon, lunch_mon, dinner_mon, ent_mon, break_tue, lunch_tue, dinner_tue, ent_tue, .....etc
I want to output the sum of the four monday columns as well as the sum of the four tuesday columns.
I did this with
SELECT break_mon+lunch_mon+dinner_mon+ent_mon AS mon_tot, break_tue+lunch_tue+dinner_tue+ent_tue AS tue_tot FROM expense_report
I now want to add mon_tot and tue_tot AS total, but SQL is telling me that it can not find mon_tot. Is there a way to do this? Thanks!
Darren MCP
SELECT mon_tot, tue_tot, mon_tot + tue_tot AS total
FROM (SELECT break_mon+lunch_mon+dinner_mon+ent_mon AS mon_tot,
break_tue+lunch_tue+dinner_tue+ent_tue AS tue_tot
FROM expense_report) AS T
Regards,
jag
> SELECT break_mon+lunch_mon+dinner_mon+ent_mon AS mon_tot, break_tue+lunch_tue+dinner_tue+ent_tue AS tue_tot FROM expense_report
I now want to add mon_tot and tue_tot AS total, but SQL is telling me that it can not find mon_tot. Is there a way to do this? Thanks!
Hi Darren,
Make your query into a derived table. (Wrap with parentheses and give
it an alias). The expense_report table really should be normalized.
In the long run, it will make your code cleaner and more maintainable.
- Louis
select mon_tot+tue_tot as total
from
(
SELECT break_mon+lunch_mon+dinner_mon+ent_mon AS mon_tot,
break_tue+lunch_tue+dinner_tue+ent_tue AS tue_tot
FROM expense_report
) as a
Thanks! I had one question! I noticed in Enterprise manager when in Design
mode, you can create a field and then add a formula right to the field. Is
this way better or worse as far as speed goes then using a query? Thanks!
"louis nguyen" <lo************@hotmail.com> wrote in message
news:b0*************************@posting.google.co m... SELECT break_mon+lunch_mon+dinner_mon+ent_mon AS mon_tot, break_tue+lunch_tue+dinner_tue+ent_tue AS tue_tot FROM expense_report
I now want to add mon_tot and tue_tot AS total, but SQL is telling me
that it can not find mon_tot. Is there a way to do this? Thanks!
Hi Darren,
Make your query into a derived table. (Wrap with parentheses and give it an alias). The expense_report table really should be normalized. In the long run, it will make your code cleaner and more maintainable. - Louis
select mon_tot+tue_tot as total from ( SELECT break_mon+lunch_mon+dinner_mon+ent_mon AS mon_tot, break_tue+lunch_tue+dinner_tue+ent_tue AS tue_tot FROM expense_report ) as a
> Thanks! I had one question! I noticed in Enterprise manager when in Design mode, you can create a field and then add a formula right to the field. Is this way better or worse as far as speed goes then using a query? Thanks!
Hi,
I think you're talking about computed columns. It depends. If all
that is required is the simple calcs, in the first post, computed cols
are fine. However, if your requirements change and you find yourself
altering code constantly, I find stored procedures the way to go. In
the long run it saves my sanity, but that's me. -- Louis This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: John Bahran |
last post by:
I am trying to use calculated fields in my query but all the results
are zero ven when they're not. Please help. Thanks.
|
by: david |
last post by:
Hi,
I have a form with a couple of calculated fields.
I want to put some code into the 'Form-Load' event to set various
object states on the form, depending on the value of these fields.
The...
|
by: TORQUE |
last post by:
Hi,
I am having some trouble with recording a field on a form into my Table after formatting it to calculate several fields on the form.
If i just put the amount in the field and have it linked...
|
by: Ryker |
last post by:
I have a Purchase Order where I have a calculated field called Price
that is calculated by multiplying Qty * Sales Price. I have 10 of
these fields...Price 1 - Price 10 (for each line of the PO). ...
|
by: Olveres |
last post by:
Hi,
I have managed to work out how to add new lines into a calculated text
box. However in this text box some of the outcome fields are empty
however when previewing the report it includes the...
|
by: Henrik |
last post by:
The problem is (using MS Access 2003) I am unable to retrieve long
strings (255 chars) from calculated fields through a recordset.
The data takes the trip in three phases:
1. A custom public...
|
by: jcf378 |
last post by:
hi all.
I have a form which contains a calculated control ("days") that outputs the # of days between two dates (DateDiff command between the fields and ).
However, when I click "Filter by...
|
by: dympna |
last post by:
Hi can anyone suggest a fix for this... as I am a novice in access.
I have created a training table with the following fields
Employee Name - joe
Training Received - Fork lift
Date Received...
|
by: Matthew Wells |
last post by:
If I have a calculated field that returns a value from a udf, does that
field get calculated even when it's not being used in a Select statement? I
knw that if a calculated field's formula is...
|
by: mkbrady |
last post by:
I have a query that includes calculated fields that generate numeric results.
I have wrapped conversion functions CLng() and CDdl() around the calculated
fields to ensure the data types are...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |