Alessandro Teruzzi
Alessandro Teruzzi

Reputation: 3978

Error running a simple sql command

I am very tired and maybe I am missing something obvious.

I got this error:

Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'select'.

Running this simple command

create table tempPosition select * from Position;

Any idea?

Thanks

P.S. sql server 2008

EDIT

my apologies I forgot a fundamental piece of information, the table has an primary key that auto-generate the id. It was that column that was causing the problem. Using the full list of columns (omitting the primary key) solved the problem. Thanks for your help.

Upvotes: 0

Views: 70

Answers (4)

Dave
Dave

Reputation: 1234

For SQL Server the format of the queries are as follows:

-- Insert And Create Table
SELECT [list items] INTO TableOut FROM TableIn

-- Create The Table Only
SELECT [list items] INTO TableOut FROM TableIn WHERE 0=1

Upvotes: 0

Jens Schauder
Jens Schauder

Reputation: 81950

create table tempPosition as select * from Position;

Upvotes: 0

agent-j
agent-j

Reputation: 27933

This creates a temporary table (good for the life of your connection, then deleted when you disconnect) containing all the contents of Position.

SELECT * 
INTO #tempPosition
FROM Position

Upvotes: 0

Charles Bretana
Charles Bretana

Reputation: 146499

Try

   Select * Into TempPosition
   From Position

Upvotes: 3

Related Questions