| Author |
Topic |
|
zhel04
Starting Member
38 Posts |
Posted - 2011-03-02 : 03:50:16
|
| Hi guys. I need help. I would like to create a new table. I have this query:CREATE TABLE TblMarkAS SELECT CM, Code, SUM ([YTD1 (Value)]), SUM ([YTD2 (Value)])FROM TblRepHowever this query gives an error Incorrect syntax near the keyword 'AS'.can someone help me what should I do? or teach me the right query?Thanks. :) God Bless. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-03-02 : 03:54:22
|
[code]select <column list>into table_namefrom <table>[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
zhel04
Starting Member
38 Posts |
Posted - 2011-03-02 : 03:56:03
|
| Thanks for the reply but i need to get the SUM of the values from the existing table to new table. How will i do that? |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2011-03-02 : 03:56:21
|
| CREATE TABLE TblMarkAS SELECT CM, Code, SUM ([YTD1 (Value)]), SUM ([YTD2 (Value)])FROM TblRep it will work in oracle but u can use simple into clause in sql server for creation of table. |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2011-03-02 : 03:59:07
|
quote: Originally posted by zhel04 Thanks for the reply but i need to get the SUM of the values from the existing table to new table. How will i do that?
SELECT CM, Code, SUM ([YTD1 (Value)]) ytd1value, SUM ([YTD2 (Value)])ytd2value into newtablenameFROM TblRep group by cm,codeit will create the table with columns cm,code,ytd1value,ytd2value |
 |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-03-02 : 03:59:09
|
quote: Originally posted by zhel04 Thanks for the reply but i need to get the SUM of the values from the existing table to new table. How will i do that?
Can be done via KH method.CheersMIK |
 |
|
|
zhel04
Starting Member
38 Posts |
Posted - 2011-03-02 : 04:00:49
|
| I want to create a new table copying the fields from the existing table however there will be a computation from it like SUM of the values. How will I do that if I'm going to use the Into statement? |
 |
|
|
zhel04
Starting Member
38 Posts |
Posted - 2011-03-02 : 04:05:50
|
quote: Originally posted by bklr
quote: Originally posted by zhel04 Thanks for the reply but i need to get the SUM of the values from the existing table to new table. How will i do that?
SELECT CM, Code, SUM ([YTD1 (Value)]) ytd1value, SUM ([YTD2 (Value)])ytd2value into newtablenameFROM TblRep group by cm,codeit will create the table with columns cm,code,ytd1value,ytd2value
No it didn't work. It gives me an error. |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2011-03-02 : 04:06:58
|
| can u post the error message |
 |
|
|
zhel04
Starting Member
38 Posts |
Posted - 2011-03-02 : 04:10:21
|
quote: Originally posted by bklr can u post the error message
Msg 1038, Level 15, State 5, Line 1An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Add a name or single space as the alias name. |
 |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-03-02 : 05:28:18
|
| there is a column having no name/alias ... provide alias to each and every column and confirm it by executing only the Select Statement.CheersMIK |
 |
|
|
kazi
Starting Member
8 Posts |
Posted - 2011-03-02 : 06:08:31
|
| SELECT CM,Code, sum(YTD1) Value1,sum(YTD2) Value2 into TblMarkFROM TblRep group by CM,CodeKazi |
 |
|
|
|