Hi
I would like to update the column of one table with the last calculated value of two columns from another table.
The tables are defined as follows:
Table #1: IM_ITEM
-----------------
ITEM_NO VARCHAR(20)
LSTFACTOR DECIMAL(15,4)
Table #2: PO_RECVR_HIST_LIN
---------------------------
ITEM_NO VARCHAR(20)
RECVR_NO VARCHAR(10)
COST DECIMAL(15,4)
RECVD_COST DECIMAL(15,4)
I run the following sql statement to display the contents:
select
RECVR_NO,
ITEM_NO,
COST,
RECVD_COST,
COST/RECVD_COST as LSTFACTOR
from PO_RECVR_HIST_LIN
where
(RECVD_COST > 0) and (ITEM_NO = 'P201F056')
RECVR_NO ITEM_NO COST RECVD_COST LSTFACTOR
-------- -------- ------- ---------- ---------
103 P201F056 429.28 199 2.1572
138 P201F056 427.65 189 2.2627
76 P201F056 439.37 199 2.2079
88 P201F056 425.835 199 2.1399
Now I run the following statement to update table #1 with the last calculated value of LSTFACTOR?
update A
set
PROF_NO_5 = B.LSTFACTOR
from
IM_ITEM A inner join
(select
top 100 percent
ITEM_NO,
COST/RECVD_COST as LSTFACTOR
from PO_RECVR_HIST_LIN
where
RECVD_COST > 0
order by CONVERT(INT, RECVR_NO) ASC) B
on A.ITEM_NO = B.ITEM_NO
It expect it to insert 2.2627 in the LSTFACTOR column of table #1 but instead it inserts 2.1572 which is the first calculated value.
What am I doing wrong?
Regards,
Georges
I would like to update the column of one table with the last calculated value of two columns from another table.
The tables are defined as follows:
Table #1: IM_ITEM
-----------------
ITEM_NO VARCHAR(20)
LSTFACTOR DECIMAL(15,4)
Table #2: PO_RECVR_HIST_LIN
---------------------------
ITEM_NO VARCHAR(20)
RECVR_NO VARCHAR(10)
COST DECIMAL(15,4)
RECVD_COST DECIMAL(15,4)
I run the following sql statement to display the contents:
select
RECVR_NO,
ITEM_NO,
COST,
RECVD_COST,
COST/RECVD_COST as LSTFACTOR
from PO_RECVR_HIST_LIN
where
(RECVD_COST > 0) and (ITEM_NO = 'P201F056')
RECVR_NO ITEM_NO COST RECVD_COST LSTFACTOR
-------- -------- ------- ---------- ---------
103 P201F056 429.28 199 2.1572
138 P201F056 427.65 189 2.2627
76 P201F056 439.37 199 2.2079
88 P201F056 425.835 199 2.1399
Now I run the following statement to update table #1 with the last calculated value of LSTFACTOR?
update A
set
PROF_NO_5 = B.LSTFACTOR
from
IM_ITEM A inner join
(select
top 100 percent
ITEM_NO,
COST/RECVD_COST as LSTFACTOR
from PO_RECVR_HIST_LIN
where
RECVD_COST > 0
order by CONVERT(INT, RECVR_NO) ASC) B
on A.ITEM_NO = B.ITEM_NO
It expect it to insert 2.2627 in the LSTFACTOR column of table #1 but instead it inserts 2.1572 which is the first calculated value.
What am I doing wrong?
Regards,
Georges