× 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.



I have not tried a CTE with an update, but you can think of a CTE as a temporary view. So you might try creating a temporary view and using that view as the source of the update data.

Here's an example--it is UNTESTED so you may need to correct the syntax:

create view qtemp/mydata as
(Select SUVNDA, SUMDL, Sum(SUTSLS) As MySls,sum(suunit) as myunit
From SUMSLSP Where SUDATE Between 20120601 and 20120901 SUSTNO =
999 And SUTYPE = 'D'
) with data
;
update WCSRTL/WCStmpP a
set tcsls =
(select mysls from qtemp/mydata b
where a.SUNVA=b.SUNVA and a.SUMDL=B.SUMDL),
set tcunit =
(select my count from qtemp/mydata
where a.SUNVA=b.SUNVA and a.SUMDL=B.SUMDL),
where exists
(select 1 from qtemp/mydata b
where a.SUNVA=b.SUNVA and a.SUMDL=B.SUMDL)

If you do try to use a CTE, remember that the "With" keyword is part of the SELECT statement. I think it might complicate things since there are two SELECT statements. But without experimentation, I can't comment further.


Sam


On 10/3/2012 12:48 PM, Michael Ryan wrote:
Anyone see why this makes STRSQL spit up?

update WCSRTL/WCStmpP set tcsls=mysls, tcunit=myunit with mydata as
(Select SUVNDA, SUMDL, Sum(SUTSLS) As MySls,sum(suunit) as myunit
From SUMSLSP Where SUDATE Between 20120601 and 20120901 SUSTNO =
999 And SUTYPE = 'D') Select SUVNDA, SUMDL, MyCount From MyData

I'm doing the same type of thing with an Insert and it works fine. I'm
getting this:

Token MYDATA was not valid. Valid tokens: ALL CS CHG NONE RR RS UR N

with the cursor at the "with mydata as" area.

Thanks!


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.