MIDRANGE dot COM Mailing List Archive



Home » MIDRANGE-L » October 2012

Re: Insert with Temp Table



fixed

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!






Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2014 by MIDRANGE dot 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 here. If you have questions about this, please contact