Execute query from select + update SQL

0

I have the following SQL:

SELECT prospect.uni_id, prospect.usu_id, prospect.pro_nome, prospect_agendamento.* FROM prospect_agendamento JOIN prospect ON(prospect.pro_id=prospect_agendamento.age_id_prospect) WHERE prospect_agendamento.age_cod_consultora_agendado = '4'

In this, I bring the results that I need. I need to execute the following UPDATE within that query:

UPDATE prospect_agendamento SET age_cod_consultora_agendado=prospect.usu_id

How can I execute one query within another?

  

I need to set the usu_id that is in the prospect table, to the   age_cod_addressed in the prospect_address table, leave   equal

    
asked by anonymous 19.02.2018 / 01:11

1 answer

2

You can do this:

UPDATE prospect_agendamento
SET age_cod_consultora_agendado = P.usu_id
FROM prospect_agendamento PA WITH(NOLOCK)
INNER JOIN propect P WITH(NOLOCK) ON PA.age_id_prospect = P.pro_id
WHERE PA.age_cod_consultora_agendado = '4'
    
19.02.2018 / 02:03