Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

SQL Server SELECT into existing table

I'm attempting to choose a few fields from one table and supplement them into an existing table from a stored procedure. Here is the thing that I am attempting:

SELECT col1, col2
INTO dbo.TableTwo
FROM dbo.TableOne
WHERE col3 LIKE @search_key


I think SELECT ... INTO ... is for temporary tables which is why I get an error that dbo.TableTwo already exists.

How can I insert multiple rows from dbo.TableOne into dbo.TableTwo?
by

3 Answers

akshay1995
It would work as given below :

insert into Gengl_Del Select Tdate,DocNo,Book,GlCode,OpGlcode,Amt,Narration
from Gengl where BOOK='" & lblBook.Caption & "' AND DocNO=" & txtVno.Text & ""
sandhya6gczb

select
into existing table database..existingtable
from database..othertables....

If you have used select * into tablename from other tablenames already, next time, to append, you say select
into existing table tablename from other tablenames
RoliMishra
IF you want an identity column in the new table created with select into then it can be done as below.

SELECT 
ID = IDENTITY(INT, 1, 1),
name
INTO table2
FROM table1

Login / Signup to Answer the Question.