Run select + update SQL query

Asked

Viewed 260 times

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 I need. I need to run the following UPDATE within this query:

UPDATE prospect_agendamento SET age_cod_consultora_agendado=prospect.usu_id

How I can execute one query within the other?

I need to set the usu_id that is in the table of Prospect, for the age_cod_consultora_scheduled in table prospect_scheduling, leave equal

  • It depends on what you need to do from one SQL to another, what you missed to say in the question?

  • I need to set the usu_id that is in the table of Prospect, for the age_cod_query scheduled in the table prospect_scheduling, leave equal

  • What is the database manager?

1 answer

2


You can do it like 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'

Browser other questions tagged

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