title: CTE with update
body: <p>This is a simple query using with CTE but is not behaving the way I want to.</p>
  
  <p>The idea is to filter those records wit precio_90 = null and then update the field precio_90 with the price from mytable2 where codigo=codigo on a specific date.
  At present I get all records updated without the actual filter.</p>
  
  <pre><code>DECLARE @mytable1 TABLE
  (
  codigo VARCHAR(10) NOT NULL,
  precio_90 NUMERIC(10, 4) 
  );
  
  DECLARE @mytable2 TABLE
  (codigo VARCHAR(10) NOT NULL,
  fecha date NOT NULL,
  precio NUMERIC(10, 4) NOT NULL
  );
  
  INSERT INTO @mytable1(codigo, precio_90)
  VALUES ('stock1', 51),
  ('stock1', 3),
  ('stock1',5),
  ('stock1',6),
  ('stock1',2),
  ('stock1',7),
  ('stock1',null)
  
  INSERT INTO @mytable2(codigo, fecha, precio)
  VALUES ('stock1', '20140710', 26),
  ('stock2', '20140711', 66),
  ('stock1', '20140712', 23),
  ('stock2', '20140710', 35);
  
  ;WITH CTE_1
  as
  ( SELECT  codigo, precio_90           
    FROM  @mytable1 
    where precio_90 is null )
  
  UPDATE t1 
  SET t1.precio_90= t2.[precio]
  from @mytable1 as t1
  INNER JOIN @mytable2 as t2
  ON t1.codigo = t2.[codigo] and '2014-07-10'=t2.fecha
  </code></pre>