I am trying to update multiple values ​​from another table with multiple two columns from two tables based on date and character

UPDATE wpcurrate
SET usd = (SELECT (mo.price * wpcurrate.midprice) as USD
           FROM mo, wpcurrate
           WHERE wpcurrate.symbol = mo.symbol)
WHERE mo.curdatetime BETWEEN '2015-07-01 12:00:00 AM' AND '2015-07-31 11:59:59 PM'

      

The following error is displayed:

Msg 4104, Level 16, State 1, Line 1
The multipart identifier "mo.curdatetime" cannot be linked.

Msg 4104, Level 16, State 1, Line 1
The multipart identifier "mo.curdatetime" cannot be linked.

+3


source to share


2 answers


You can try this code:



UPDATE wp
SET wp.usd = m.price * wp.midprice
FROM wpcurrate AS wp
    INNER JOIN mo AS m ON wp.symbol = m.symbol
WHERE m.curdatetime BETWEEN '2015-07-01 12:00:00 AM' AND '2015-07-31 11:59:59 PM'

      

+1


source


UPDATE w
SET w.usd = mo.price * w.wpcurrate.midprice
                 FROM wpcurrate w
Inner Join mo on w.symbol = mo.symbol
WHERE mo.curdatetime  between  '2015-07-01 12:00:00 AM' and '2015-07-31 11:59:59 PM'

      



To achieve this goal, you need to perform a join operation

+1


source







All Articles