Solved

create a new table from view

Posted on 2014-01-11
3
324 Views
Last Modified: 2014-01-12
Hi Experts
i am trying to copy the content of the view to a new table

i am using this query

CREATE TABLE temp_Courses
  AS (SELECT distinct(Description) FROM [Training].[dbo].[masCourse]);

Open in new window


and i am getting this error
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'AS'.

i even tried this
  SELECT Description
INTO temp_courses
FROM (SELECT distinct Description FROM [Training].[dbo].[masCourse])

Open in new window


also not working i am getting this error
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near ')'.

Open in new window


can you help me please
0
Comment
Question by:AZZA-KHAMEES
3 Comments
 
LVL 21

Assisted Solution

by:Dale Burrell
Dale Burrell earned 250 total points
ID: 39774364
I don't think you can create a table and insert into it at the same time - unless its a recent feature I haven't used.

The following should work to create you a temp table with the results in it:

SELECT distinct(Description)
INTO #temp_courses
FROM [Training].[dbo].[masCourse]

Open in new window

0
 
LVL 40

Accepted Solution

by:
Sharath earned 250 total points
ID: 39774370
If you already have the table, try this.
INSERT temp_Courses
SELECT distinct Description FROM [Training].[dbo].[masCourse];

Open in new window

If you don't have the table, you can try SELECT INTO and create new table
 SELECT distinct Description
   INTO temp_courses
   FROM FROM [Training].[dbo].[masCourse]

Open in new window

0
 

Author Closing Comment

by:AZZA-KHAMEES
ID: 39774379
thanks
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how the fundamental information of how to create a table.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question