I need to insert data into a table in another table. Basically I need to do this:
INSERT INTO Consulta (tipo, busqueda1, resultado1, resultado2, resultado3)
The value of the field tipo
is defined by me, but the values of the other fields are extracted from the following query:
SELECT CODIGO_USUARIO, Electrodomestico, Cant FROM (SELECT CODIGO_USUARIO, [Abanico Mesa], [Abanico Techo], [Estufa Elect 1F] FROM TempCensoElect) p UNPIVOT (Cant FOR Electrodomestico IN ([Abanico Mesa], [Abanico Techo], [Estufa Elect 1F])) AS unpvt
Resulting in the following:
The data in the CODIGO_USUARIO
column must be inserted in the busqueda1, resultado1
fields. The data in the Electrodomestico
column must be inserted in the resultado2
field and the data in the Cant
column must be inserted in the resultado3
How can I do this?