Insert with two different selects

Asked

Viewed 763 times

2

That one of mine 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 generated in hand the value of the first field and even then it didn’t 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
  • Just one question, I don’t know if I’m going outside the scope, I don’t think so, but when I’m going to enter a date, it gives me this mistake. Mensagem 8152, Nível 16, Estado 14, Linha 19
String or binary data would be truncated.
The statement has been terminated.

1 answer

6


Lacked transform their sub-select in a select valid for the clause Values:

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 lines using INSERT and SELECT

Browser other questions tagged

You are not signed in. Login or sign up in order to post.