Sql Server, duvida inserir dados em tabela existente via QUERY/SELECT

SQL Server

12/04/2016

Boa Tarde,
Gostaria de saber, se existe alguma solução para tal problema,
creio que seja algo simples como um BULK INSERT ou um INSERT INTO, porem não obtive sucesso, até o momento.

Tenho 10 tabelas, e preciso fazer um select simples nelas, e unir os resultados dos selects todos em uma tabela só,
até hoje faço manual, separo os resultados em TXT, e realizo o BULK INSERT nesta planilha padrão.

existiria alguma solução para que o resultado da QUERY seja adicionada automaticamente na tabela padrão?

obrigado desde já!
forte abraço!
Arthur Micheloni

Arthur Micheloni

Curtidas 0

Melhor post

Raylan Zibel

Raylan Zibel

12/04/2016

Costuma funcionar:
insert into tabela_destino (codigo, nome, idade, telefone) 
select codigo, nome, idade, telefone from tabela_origem;
GOSTEI 1

Mais Respostas

Jair N.

Jair N.

12/04/2016

Boa Tarde, por curiosidade, você tem a pasta ".../data/..." ? você sabe a versão do PostgreSQL que estava sendo utilizado?
Bem em tudo tem macetes e gambiarras que ajudam a resolver, eu mesmo tenho meu método personalizado de recuperação, principalmente de bases bichadas que não conseguem fazer backup...
GOSTEI 0
Arthur Micheloni

Arthur Micheloni

12/04/2016

então uso o SQL SERVER 2012,
GOSTEI 0
Arthur Micheloni

Arthur Micheloni

12/04/2016

Costuma funcionar:
insert into tabela_destino (codigo, nome, idade, telefone) 
select codigo, nome, idade, telefone from tabela_origem;


dai eu add o where depois disso?
vou testar
GOSTEI 0
Arthur Micheloni

Arthur Micheloni

12/04/2016

graças a ajuda do amigo, cheguei a este artigo que me mostrou a principal diferença e o erro besta que eu estava cometendo,
gratidão!
Differences

INSERT INTO SELECT inserts into an existing table.
SELECT INTO creates a new table and puts the data in it.
All of the columns in the query must be named so each of the columns in the table will have a name. This is the most common mistake I see for this command.
The data type and nullability come from the source query.
If one of the source columns is an identity column and meets certain conditions (no JOINs in the query for example) then the column in the new table will also be an identity.


Basic syntax

INSERT INTO SELECT

CREATE TABLE MyTable (name varchar(255));
GO
INSERT INTO MyTable
SELECT name
FROM sys.databases;
GO

SELECT INTO

SELECT name INTO MyTable
FROM sys.databases;
GO

fonte: https://www.toadworld.com/platforms/sql-server/b/weblog/archive/2014/12/03/insert-into-select-vs-select-into
GOSTEI 0
POSTAR