SQL Server - Insert record block to a table with data from other tables

0

Good morning, I hope you can help me since I am just beginning to apply in what is SQL Server, I am working in a system of worksheet and I wanted to know how to insert in a table (Template.dbf) some data of the table (worker.dbf) plus some other field of another table, ojito that are tables with different fields,

Well, as you can see in the image, my idea is that when you insert a month, you automatically register in the table table.dbf with the data of the workers table, with the field of the month (id_planilla) and the percentage that depends on the salary field.

I do not know whether to do it with a stored procedure that contains a Trigger or a cursor or with the combination of both.

I hope you can help me. Greetings and thanks

    
asked by Angela 01.09.2017 в 17:44
source

1 answer

0

Ready, based on your example, the sentence should be like this:

INSERT INTO Planilla 
VALUES (id_plantilla, id_trabajador, porcentaje)
SELECT Mes.id_mes, 
    Trabajador.id_trabajador, 
    Trabajador.formula_porcentaje  --  Esta columna es solo un ejemplo para el calculo de tu porcentaje.
FROM Mes, Trabajador
WHERE Mes.id_mes = '01'  --  En caso de que tengas una condición.

With this you can generate an insert in a table from multiple tables. It is enough to define the columns that will obtain values in VALUES and that in the SELECT they will be the same, by data type and length. Greetings.

    
answered by 01.09.2017 / 18:17
source