How does one combine the SELECT and INSERT INTO commands and insert the results into a temporary table in SQL Server?
Something like this:
INSERT INTO #TempTable
SELECT * FROM MyTable;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You got two options. First one is to create your temp table and then use
INSERT INTO…SELECT, like this:The second option is to insert directly in a new temp table:
Big difference is that using method 1, you need to specify all the columns in your temp table in advance. Method 2 gives you a temp table that automatically has all the columns of your
OtherTable.