Use "WHERE" as a subquery with INSERT

0

My idea is to be able to insert the sum between 2018-07-12 and 9 days ( SELECT "" + interval 9 day) ) in the column fechaFin of the same table.

But first I want to identify a row of T_tarifa with where but it is not allowed.

Is there a different way to do the same? Can not the where be used after an operation with parentheses?

insert into T_tarifa (fechaFin)  values  (SELECT "2018-07-12" + interval 9 day) where regimen="desayuno
  

Resolved:

INSERT INTO T_tarifa (precioNoche,fechaInicio,fechaFin,tarifa) values ((SELECT precio  FROM T_tiphab  where codHotel="1" and tipo="camasimple"),"2018-11-01",( "2018-11-01" + interval 9 day),4  * (select precio from T_tiphab where tipo="camasimple" and codHotel= 1));
    
asked by TOMAS 21.03.2018 в 21:29
source

2 answers

2

It is not well understood what you want to do. If what you want to do, is to modify records that already exist in the T_tarifa table, the statement should be UPDATE .

UPDATE T_tarifa set fechaFin = (SELECT "2018-07-12" + interval 9 day as fechaFin) WHERE regimen="desayuno"

If, instead, what you want to do is apply a filter on the SUB SELECT that is going to insert the data in the table T_tafifa , you should take the parenthesis and make a INSERT .. SELECT normal.

Now: the field regimen that you put in the WHERE does not exist in the table generated by SELECT "2018-07-12" + interval 9 day , and therefore, it will break you.

The INSERT statement is applied to records that do not yet exist in the database (that is, create new records). Therefore, INSERT ... WHERE has no logic.

    
answered by 21.03.2018 в 21:43
0

I do not really understand what you want to do, but to make the sum of the Dates I think this can help you:

Select DateAdd(Day, 9, '2018-07-12')
    
answered by 21.03.2018 в 22:33