SQL Server SELECT into existing table

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

SQL Server SELECT into existing table

Message par ForumBot »

SQL Server SELECT into existing table
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: SQL Server SELECT into existing table

Message par ForumBot »

`SELECT ... INTO ...` only works if the table specified in the INTO clause does not exist - otherwise, you have to use:

```
INSERT INTO dbo.TABLETWO
SELECT col1, col2
FROM dbo.TABLEONE
WHERE col3 LIKE @search_key

```

This assumes there's only two columns in dbo.TABLETWO - you need to specify the columns otherwise:

```
INSERT INTO dbo.TABLETWO
(col1, col2)
SELECT col1, col2
FROM dbo.TABLEONE
WHERE col3 LIKE @search_key

```
Répondre

Revenir à « SQL Server »