Click to See Complete Forum and Search --> : What is wrong with the sql statement?
dullboy
January 28th, 2005, 08:07 PM
I wanted to create a table which copies the structure of another table without coping its data in Microsoft SQL server.
create table temEmployee
as
select * from employee
where 1=2
However there is an error "Incorrect syntax near the keyword 'as'."
What is wrong? Thanks in advance.
Sahir
January 28th, 2005, 10:27 PM
In MS Access
select tblEmployee.field1, tblEmployee.field2 into tblTmpEmployee
from tblEmployee
where tblEmployee.field1 = 'something'
Oracle
create table tblTempEmp as select tblEmp.field1, tblEmp.field2 from
tblEmp where tblEmp.field1 = 'something '
SQL Server - no idea, but my guess is the syntax could be similar to MS Access.
erickwidya
January 28th, 2005, 10:58 PM
..is an error "Incorrect syntax near the keyword 'as'."
if u want to use AS keyword..u have to specifies Alias Name for the represented field
but u using Create SQL..i supposed u want to create new table
from MSDN
SELECT field1[, field2[, ...]] INTO newtable [IN externaldatabase]
FROM source
The SELECT...INTO statement has these parts:
Part - Description
field1, field2 - The name of the fields to be copied into the new table.
newtable - The name of the table to be created. It must conform to standard naming conventions. If newtable is the same as the name of an existing table, a trappable error occurs.
externaldatabase - The path to an external database. For a description of the path, see the IN clause.
source - The name of the existing table from which records are selected. This can be single or multiple tables or a query.
cheers
Madhi
January 29th, 2005, 12:53 AM
Try this
select * into tmpEmployee from employee where 1=2
Madhivanan
Otto Drunkencoder
January 29th, 2005, 08:57 AM
Try this
select Emp.field1, Emp.field2 into tempEmp from Emp where 1 = 2
dullboy
January 29th, 2005, 12:54 PM
You are right! Thank you very much!
Try this
select * into tmpEmployee from employee where 1=2
Madhivanan
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.