How to insert a value in a table copy?

Asked

Viewed 27 times

-2

I’m performing a table transfer "Histo_Ficha_Controle" for "Cad_Espec_Teste". The two tables contain the same fields to receive the information. When copying from one table to another, I would like to know if it is possible to insert a value into one of the columns.

insira o código aqui
String query1 = "INSERT INTO Cad_Espec_Teste (ORDEM,ESP_LINHA ,ESP_MATERIAL ,ESP_TESTE ,ESP_EQUIPAMENTO ,MINIMO ,MAXIMO ,UNID_MEDIDA ,TEXTO ,REFERENCIA ,FREQUENCIA ,"
                    + "UNID_FREQUENCIA,PRODUTO ,ORIGEM ,TIPO_ESPEC ,ESPEC_COMPLETO ,FREQ_COMPLETO ,LAB ,COMPLEMENTO,RESPONSAVEL_ALTER,PENDENCIA_ALTER ,DATA_ALTER,OBSERVACAO_ALTER,"
                    + "DATE_VALIDE_ALTER,ALTER_IDENTIFICACAO) SELECT ORDEM,HISTO_LINHA,HISTO_MATERIAL,HISTO_TESTE,HISTO_EQUIPAMENTO,HISTO_MINIMO,HISTO_MAXIMO,"
                    + "HISTO_UNID_MEDIDA,HISTO_TEXTO,HISTO_REFERENCIA,HISTO_FREQUENCIA,HISTO_UNID_FREQUENCIA,HISTO_PRODUTO,HISTO_ORIGEM,HISTO_TIPO_ESPEC,HISTO_ESPEC_COMPLEMENTO,"
                    + "HISTO_FREQ_COMPLETO,HISTO_LAB,HISTO_COMPLEMENTO,HISTO_RESPONSAVEL,HISTO_PENDENCIA,HISTO_DATA_HISTO,HISTO_OBSERVACAO,HISTO_DATE_VALID,"
                    + "ALTER_IDENTIFICACAO FROM Histo_Ficha_Controle WHERE HISTO_MATERIAL='" + txt_perfil.getText() + "' and HISTO_DATA_HISTO='"+txt_data.getText()+"'";

This is the String I’m using to transfer a jtable to another and would like to insert the following value: "Version Change" in the column "PENDENCIA_ALTER"

  • Your doubt remains obscure. You don’t provide enough data to analyze what you need to know, this string doesn’t collaborate on virtually anything in understanding the problem. Provide more relevant code to better understand the problem

  • And you don’t need to copy an entire table to another, in case JTable, if you want the same data in two different tables, to replicate or use the same TableModel for both of us.

  • As you can see I have 2 tables, a call Histo_ficha_control that in the case is my table of History and the other and Cad_espec_teste .. when I make a change to Cad_espec_teste table information, I save a copy in History.. in this case I am bringing an old version to replace the current one and for this I am putting a status in pendencia to be visualized.

  • So it would be interesting to add this explanation to the question too, because it gave to better understand the problem through it.

1 answer

0


In his select just you can write 1 text and it will be replicated in all lines, I did without assigning 1 value to string and indented for easy viewing

INSERT INTO Cad_Espec_Teste 
    (ORDEM,ESP_LINHA ,ESP_MATERIAL ,ESP_TESTE ,ESP_EQUIPAMENTO ,MINIMO ,MAXIMO ,UNID_MEDIDA ,TEXTO ,REFERENCIA ,FREQUENCIA
    UNID_FREQUENCIA,PRODUTO ,ORIGEM ,TIPO_ESPEC ,ESPEC_COMPLETO ,FREQ_COMPLETO ,LAB ,COMPLEMENTO,RESPONSAVEL_ALTER,PENDENCIA_ALTER ,DATA_ALTER,OBSERVACAO_ALTER
    DATE_VALIDE_ALTER,ALTER_IDENTIFICACAO) 
SELECT 
    ORDEM,HISTO_LINHA,
    HISTO_MATERIAL,
    HISTO_TESTE,
    HISTO_EQUIPAMENTO,
    HISTO_MINIMO,
    HISTO_MAXIMO
    HISTO_UNID_MEDIDA,
    HISTO_TEXTO,
    HISTO_REFERENCIA,
    HISTO_FREQUENCIA,
    HISTO_UNID_FREQUENCIA,
    HISTO_PRODUTO,
    HISTO_ORIGEM,
    HISTO_TIPO_ESPEC,
    HISTO_ESPEC_COMPLEMENTO
    HISTO_FREQ_COMPLETO,
    HISTO_LAB,
    HISTO_COMPLEMENTO,
    HISTO_RESPONSAVEL,
    'Troca de Versão', -- aqui o texto
    HISTO_DATA_HISTO,
    HISTO_OBSERVACAO,
    HISTO_DATE_VALID
    ALTER_IDENTIFICACAO 
FROM Histo_Ficha_Controle 
WHERE HISTO_MATERIAL= x and HISTO_DATA_HISTO= y
  • Thank you so much for the @Barbetta tip and solution, solved my problem!

  • @Gabrielbispo Dispo. Don’t forget to accept the answer - https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079

Browser other questions tagged

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