SQL SERVER – SELECT INTO a Table Variable in T-SQL


 

Recently one of my oldest clients of Comprehensive Database Performance Health Check asked me a very interesting question about a table variable and SELECT INTO. The question was it is possible to do SELECT INTO a Table Variable in T-SQL? The answer is it is not possible at all. Let us understand what we can do in a similar situation.

SELECT INTO a Table Variable

The DBA at the client-side was trying to do the following:

SELECT CityName
INTO @Table1
FROM [Application].[Cities]

However, anytime when they were running this query the error which they were getting was as follows:

Msg 102, Level 15, State 1, Line 2
Incorrect