Insert SELECT in a table

0

I'm trying to insert all the fields with a specific id into a table, I get this data from a select, I want to put them in a table to make queries with the data in this table as a reference. This is what I have

declare @json varchar(max) = 'esto es un json del diablo'
---SELECT DISTINCT parent_id, NAME, stringValue
--FROM parseJSON(@json) 

SELECT DISTINCT *
FROM parseJSON(@json) 
--WHERE parent_ID = 1


select min(parent_id) as p_id 
from parseJSON(@json) 
group by parent_id
having min(parent_id) = max(parent_id) 
order by parent_id
-- hasta aquí todo bien esta consulta me da los ids
-- que existen dentro del json, pero ahora necesito
-- tomar esto valores y agregarlos a idstemp


IF OBJECT_ID('idstemp') is not null DROP TABLE idstemp


CREATE TABLE idstemp(
	id int 
);

 Insert into idstemp
 (id)
 values
 (
 select min(parent_id) as p_id 
from parseJSON(@json) 
group by parent_id
having min(parent_id) = max(parent_id) 
order by parent_id
 )

    
asked by E.Rawrdríguez.Ophanim 11.09.2018 в 20:36
source

2 answers

1

You need to make a select into

In this case, the sql server is called "insert into-select"

Create the table and fill it with the result

link

EDIT: check well how it is written, since I see that you have parentheses nesting the Query etc.

PD; If you want to create a temporary table, you can do it with the #

mark

Select FieldA...FieldN into #MyTempTable from MyTable

    
answered by 11.09.2018 / 20:40
source
1

In this case you should use the INSERT INTO SELECT in SQL SERVER , more or less it would be something like this:

INSERT INTO AEROLINEA
SELECT IDCODIGO, LINEA
FROM AEROCHILE
GO

I leave a link. Greetings

  

link

    
answered by 27.09.2018 в 00:13