Re: Update Query & Expression Help
From: MGFoster (me_at_privacy.com)
Date: 01/04/05
- Next message: Tom Ellison: "Re: Flexible "Matrix" query"
- Previous message: MGFoster: "Re: Error"
- In reply to: Bobo: "Update Query & Expression Help"
- Next in thread: Bobo: "Re: Update Query & Expression Help"
- Reply: Bobo: "Re: Update Query & Expression Help"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 04 Jan 2005 23:36:10 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
What you are trying to do is usually a BAD design in RDMSs 'cuz a
calculated column is generally calculated during a SELECT (report)
query.
Checking 4 column values to find the Max value probably means the design
of that table is incorrect. Since the resultant max value is the final
value, that means those 4 values have the same meaning and should be in
one column. Instead of a table something like this:
create table test (
AccountID integer ,
Year integer ,
Qtr1 money,
Qtr2 money,
Qtr3 money,
Qtr4 money
Max_Qtrs money,
constraint pk_test primary key (accountid, [year])
)
You should have something like this:
create table test (
AccountID integer ,
[Year] smallinteger ,
Qtr byte,
Value money,
Constraint pk_test primary key (accountid, [year], qtr)
)
To find the max qtr value in 2004 you do something like this:
SELECT AccountID, max(value)
FROM test T
WHERE [year] = 2004
GROUP BY accountid
========== But to answer your question here're 2 updates:
=== Getting the max value of 4 columns:
UPDATE master_table
SET highest_max = IIf(col1 > col2 and col1 > col3 and col1 > col4, col1,
IIf(col2 > col1 and col2 > col3 and col2 > col4, col2,
IIf(col3 > col1 and col3 > col2 and col3 > col4, col3,
IIf(col4 > col1 and col4 > col2 and col4 > col3, col4
))))
WHERE ... criteria ...
=== Setting one column value = result of 2 other columns:
UPDATE master_table
SET col5 = col7 * col8
WHERE ... criteria ...
-- MGFoster:::mgf00 <at> earthlink <decimal-point> net Oakland, CA (USA) -----BEGIN PGP SIGNATURE----- Version: PGP for Personal Privacy 5.0 Charset: noconv iQA/AwUBQdsob4echKqOuFEgEQL0GACgzm+iTpmQxbKNMRfNDt+DGsF0X+MAoNbd 7KWDwtwu9NV3kT0W7lgYMB9L =R/m9 -----END PGP SIGNATURE----- Bobo wrote: > I have a Query I want to run, to update a field in the MASTER table. I have to > examine 4 fields each record of MASTER to find the Highest Max value; then I > want to update MAX SCORE in the MASTER table with the value. > > I also need to take 2 different fields of a record, multiply the values > together, and plug the result into another field in the Master table. > > I have tried to create some Update queries but I've been unsuccessful so > far, I keep getting an error. > Please can anyone help
- Next message: Tom Ellison: "Re: Flexible "Matrix" query"
- Previous message: MGFoster: "Re: Error"
- In reply to: Bobo: "Update Query & Expression Help"
- Next in thread: Bobo: "Re: Update Query & Expression Help"
- Reply: Bobo: "Re: Update Query & Expression Help"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|