Reputation: 2305
I'm trying to create a new table from a select but it isn't working. Here is my syntax
select *
into newtable
from oldtable
where oldtable.number=2
Then, when I try to use it
select * from newtable
it tells me that newtable is an invalid object.
Upvotes: 0
Views: 211
Reputation: 6244
Try this:
insert into newtable
select *
from oldtable
where oldtable.number=2
Upvotes: 0
Reputation: 46
Are you in the right database, and not in the master?
Try this:
USE [your database name]
GO
SELECT *
INTO newtable
FROM oldtable
WHERE [number] = 2
If newtable has a red underline, you can still select from it. The underline just means that the table name is not cached. You can rebuild IntelliSense by pressing CTRL+SHIFT+R and the underline will disappear.
Hope this helps.
Upvotes: 2