1
Please, I am trying to make an Insert in a temporary table but this giving the error reported below:
code used for insertion
insert into #basehot(email)
select distinct a.email from #email a right join #basehot b on a.cod_pes = b.cod_pes
where a.ordem = 1
code error:
Mensagem 515, Nível 16, Estado 2, Linha 52
Cannot insert the value NULL into column 'COD_PES', table 'tempdb.dbo.#BASEHOT____________________________________________________________________________________________________________00000000A8FD'; column does not allow nulls. INSERT fails.
The statement has been terminated.
the column COD_PES is numerical ?
– Edvaldo Lucena
"Cannot Insert the value NULL into column 'COD_PES'", you are trying to insert a null value in the column
COD_PES
that does not accept null.– Woss
You are giving select only in email, so you are only entering the email field, and you cannot leave COD_PES null.
– Pedro Afonso
The Cod_pes column is numeric, and I am only selecting the email because the information already exists in the cod_pes field I am just wanting to fill in the email.
– EltonSilva
If the record already exists in the table #basehot then you should use
UPDATE
and notINSERT
to update the email field only.– anonimo
Good morning, I tried to do with the update but I am not able to do as it is giving the following error if you can help me please: Code
update #BASEHOT set email = 
(select distinct a.email from #email a inner join #BASEHOT b on a.COD_PES=b.COD_PES 
)
Error:Mensagem 512, Nível 16, Estado 1, Linha 52
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Thank you.– EltonSilva