×
The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.
Not sure if you can use CTE inside an UPDATE. Try this instead:
update File2 A set Date01 =
(select max_date
from
(select Key1, max(datefield) as Max_Date
from filea
where a_code = 'K45'
group by Key1
order by Key1) as t1
where t1.Key1 = A.Key2)
where exists
(select 1
from
(select Key1, max(datefield) as Max_Date
from filea
where a_code = 'K45'
group by Key1
order by Key1) as t1
where t1.Key1 = A.Key2)
Elvis
Celebrating 10-Years of SQL Performance Excellence
http://centerfieldtechnology.com/training.asp
-----Original Message-----
Subject: SQL Update confusion
OK you SQL gurus;
I have searched for the last couple of hours, but not finding the solution I
want. I have a file that I want the latest date from, so I am using the
max() to get the latest date. I want to update a 2nd file date field with
the results of the first file. I am wanting to do this all in the query, and
not create actual temporary files.
Am I on the right track with the following code? I am getting and error
"Keyword UPDATE not expected." I'm on V5R4.
I have something like this;
with T1 as
(select Key1, max(datefield) as Max_Date
from filea
where a_code = 'K45'
group by Key1
order by Key1)
update File2
set Date01 = (select max_date from t1
where Key1 = Key2)
where exists(select 1 from t1
where Key1 = Key2)
As an Amazon Associate we earn from qualifying purchases.