Insert with two different selects

2

My insert is not working.

insert into t_cmo_oit1980 (id_oit, id_exm_rea) 
    select max(id_oit) + 1 from t_cmo_oit1980,
    select id_exm_rea from t_cmo_Exame_Realizado where id_exm = 3936 and id_xfc = 39517;
    go

I made a gambi and managed the value of the first field in my hand and it still did not work. I did so:

insert into t_cmo_oit1980 (id_oit, id_exm_rea) 
    6574,
    select id_exm_rea from t_cmo_Exame_Realizado where id_exm = 3936 and id_xfc = 39517;
    go
    
asked by anonymous 18.04.2017 / 21:46

1 answer

6

You have failed to transform your sub-select to a select valid for the Values clause:

insert into t_cmo_oit1980 (id_oit, id_exm_rea) 
    select 
      (select max(id_oit) + 1 from t_cmo_oit1980),
      (select id_exm_rea from t_cmo_Exame_Realizado where id_exm = 3936 and id_xfc = 39517);
    go

Reference: Adding rows using INSERT and SELECT

    
18.04.2017 / 21:51