Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Updates in a Table A with Max(date) from Table B 1

Status
Not open for further replies.

DFW1999

Programmer
Nov 11, 2002
31
US
Hello,

I need to update three fields of Table_A with the two fields of Table_B and with one constant 'M'.

I have the following query to update three fields in table_A:

UPDATE TABLE_A
SET CREATE_TIMESTAMP=(SELECT MAX(CREATE_TIMESTAMP) FROM TABLE_B
SET UPDATE_TIMESTAMP=(SELECT MAX(UPDATE_TIMESTAMP) FROM TABLE_B
SET DATA_DATE=(SELECT MAX(DATA_DATE) FROM TABLE_B
SET ACTION_CODE='M';

I am getting follwoing errors:
" something needs to be between ( and SLECET "
AND
"Aggregation is not allowed in this update"

Any suggestions ?

thanks




 
1. There's only 1 SET
2. You can't use scalar subqueries in Teradata SQL

Untested:

UPDATE TABLE_A
FROM
(
SELECT
MAX(CREATE_TIMESTAMP) as maxCreate,
MAX(UPDATE_TIMESTAMP) as maxUpd,
MAX(DATA_DATE) as maxDate
FROM TABLE_B
) dt
SET
CREATE_TIMESTAMP=maxCreate,
UPDATE_TIMESTAMP=maxUpd,
DATA_DATE=maxDate
;


Dieter
 
Just an updated/revised query for multiple updates to a table A wiht max values of table B.

Still getting max aggregated functions is not allowed here.


UPDATE TABLE_A
FROM TABLE_A , TABLE_B
SET CREATE_TIMESTAMP = max(TABLE_B.CREATE_TIMESTAMP)
,UPDATE_TIMESTAMP = max(TABLE_B.UPDATE_TIMESTAMP)
,ACTION_CODE='M'
WHERE
TABLE_A.colA = TABLE_B.colA

Any suggestions would be appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top