sql - CTE with update -
This is a simple query to use with CTE, but the way I want it is not doing.
Consider those record wit precio_90 = to filter the tap and then update the field with the value from precio_90 mytable2 where codigo = codeos on a specific date currently receives all the record updates without the actual filters Are there.
DECLARE @ mytable1 table (codigo VARCHAR (10) no, precio_90 NUMERIC (10, 4)); DECLARE @ mytable2 table (codigo varchar (10) no, zero date not zero, precio NUMERIC (10, 4) no) tap; INSERT @ mytable1 (codigo, precio_90) value ('stock 1', 51), ('stock 1', 3), ('stock 1', 5), ('stock 1', 6) , 2) ('stock 1', '20140710', 26), ('stock 2', '20140711', 66) ('stock 1', 7), ('stock 1', empty) mytable2 (codeĊ, fade , Priyoo) INSERT values, ('stock 1', '20140712', 23), ('stock 2', '20140710', 35); ; As in CTE_1 (SELECT codigo, precio_90 FROM @ mytable1 where precio_90 is zero) Update t1 SET t1.precio_90 = t2. Join [Precio] @ mytable1 to t1 INNER as @ mytable2t2 at t2.codigo = t2. [Codigo] and '2014-07-10' = t2.fecha
Good, First of all, do not use CTT anywhere in your updates, which is why your results are not filtered correctly. Second, you do not need CTT for this ... You can filter precio_90 zero in the update.
UPDATE t1 SET t1.precio_90 = t2 [Precio] @ mytable1 to t1 INNER Join @ mytable2 on T2 as t1.codigo = t2.codigo where t1.precio_90 is zero and ' 2014-07-10 "= T. 2. Check
Comments
Post a Comment