Hi everybody need help on the possibility creating a new table from the results of a view or query? below is my table named table1
ID col1 col2
1 a a
2 b d
3 c f
this would be my new table named table2
ID col1 col2 col3
1 a a aa
2 b d bd
3 c f cf
this new table has an additional column by concatenating col1+col2
tried this procedure but is not working
CREATE TABLE AS (SELECT ID, COL1, COL2, COL1+COL2) TABLE2
thanksare you sure you need to store the concatenation in a separate table?SELECT ID, COL1, COL2, COL1+COL2 AS COL3
INTO TABLE2
FROM TABLE1|||thanks Rudy
yes I'll be storing the concatenated field in a new table
will that procedure create automatically the table2 even if i don't use CREATE TABLE?
alex
Showing posts with label col1. Show all posts
Showing posts with label col1. Show all posts
Tuesday, March 27, 2012
Sunday, March 25, 2012
Create Table
Can i create a table using the structure of an existing table, instead of defining the columns one by one?
e.g.
I already have table1(col1 int,col2 char(3))
I want to create another table with the same structure as table 1 without doing the following:
create table table2(col1 int,col2 char(3))
Is there a command of doing create table2 as table1 let say?Depending on the size of the table you could do the following:
select * into newtable from oldtable|||if you don't want to include data in newtable, you should modify the query as below:
select * into newtable from oldtable where 0=1|||Just what I was going to add:
If you want table structure and data then
select * into newtable from oldtable
else
select * into newtable from oldtable where (statement is false)
e.g.
I already have table1(col1 int,col2 char(3))
I want to create another table with the same structure as table 1 without doing the following:
create table table2(col1 int,col2 char(3))
Is there a command of doing create table2 as table1 let say?Depending on the size of the table you could do the following:
select * into newtable from oldtable|||if you don't want to include data in newtable, you should modify the query as below:
select * into newtable from oldtable where 0=1|||Just what I was going to add:
If you want table structure and data then
select * into newtable from oldtable
else
select * into newtable from oldtable where (statement is false)
Subscribe to:
Posts (Atom)