How to save data from a column and then overwrite it again? SQL Server

Asked

Viewed 144 times

0

I need to save data from a table to a database command and return that data to the same table after a while...

Dados que precisam ser salvos

I thought I’d do something like this:

DECLARE @NOME_FILIAL VARCHAR(25);
DECLARE @DATA_AJUSTE DATETIME;
DECLARE @CODIGO_FILIAL CHAR(6) = '300135';

    SET @NOME_FILIAL = (SELECT FILIAL FROM FILIAIS WHERE COD_FILIAL = @CODIGO_FILIAL);

    SET @DATA_AJUSTE = (SELECT DATA_AJUSTE FROM ESTOQUE_PRODUTOS 
    WHERE FILIAL = @NOME_FILIAL AND DATA_AJUSTE IS NOT NULL
    GROUP BY DATA_AJUSTE)

    UPDATE ESTOQUE_PRODUTOS SET DATA_AJUSTE = '20190309'
    WHERE FILIAL = @NOME_FILIAL AND DATA_AJUSTE IS NOT NULL

    DELETE FROM LJ_ETL_REPOSITORIO WHERE ID_ETL_TIPO='171'
    AND FILTRO LIKE '%' + @NOME_FILIAL + '%'

    PRINT @DATA_AJUSTE

UPDATE LJ_ETL_ARQUIVO SET PROCESSADO = '1'
WHERE ID_ETL_TIPO = '6'
AND CODIGO_FILIAL = @CODIGO_FILIAL

The problem is that the data in the DATE _ADJUSTMENT column will not always be the same.... I would really appreciate it if you could help me out.......

  • Take a back-up of the table, change as you like, back-up at the end of everything. Or is that not what I meant?

  • I can’t do this because the bank communicates with another, at the time of returning bkp will surely be a problem....

  • why not put it in a temporary table?

  • Save the content in another column !? I don’t know if I understand the problem.

  • One possibility is to make all changes within a transaction and at the end give a ROLLBACK instead of a COMMIT.

No answers

Browser other questions tagged

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