Quantcast
Channel: Update - Insert
Viewing all articles
Browse latest Browse all 22

Update - Insert

$
0
0
Ola Rombesso,

Sendo assim basta vc completar o restante dos campos de sua tabela...

CREATE PROC usp_atualiza_log
as

begin try
    --trata existentes
    if exists(select top 1 1 from Pessoa_Fisica_Old a with(nolock) inner join Pessoa_Fisica_New b with(nolock) on a.NPF = b.NPF)
    begin
        update a
        set a.campo1=b.campo1,
            a.campo2=b.campo2,
            a.campo3=b.campo3,
            a.campo4=b.campo4
        from Pessoa_Fisica_Old a inner join Pessoa_Fisica_New b on a.NPF = b.NPF
    end
    -- insere não existentes
    if exists(select top 1 1 from Pessoa_Fisica_New with(nolock) WHERE NPF not in (select NPF from Pessoa_Fisica_Old with(nolock)))
    begin
        insert into Pessoa_Fisica_Old
        select campo1,campo2,campo3,campo4
       from Pessoa_Fisica_New WHERE NPF not in (select NPF from Pessoa_Fisica_Old with(nolock))
    end
end try
begin catch
    select error_message()
end catch
OBS: vc pode usar o INTERSECT e EXECPT como parte da solução no lugar dos "not in"...

Att.
Marcelo Fernandes
MCP, MCDBA, MCSA, MCTS. Se útil, classifique!!!

Viewing all articles
Browse latest Browse all 22

Latest Images

Trending Articles





Latest Images