我的目标是通过在所有现有列上应用标量倍数(贴现率)来操作现有数据库表,以生成现值。然后我希望输出为一个新表。
alter table dbo.[DBO]
add scalar as power(0.95,(9 + cast([rowno] as float))/12);
create table [Table] as
(select
ID,
sum([Column I] * scalar) as newI,
sum([Column J] * scalar) as newJ
from dbo.[DBO]
group by ID);
当运行下面的代码时,返回以下错误消息:
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near '('.
这个错误似乎与"(select"有关,但我无法进行适当的编辑来解决它。
您正在尝试使用select语句创建数据表。您需要首先创建表结构:
CREATE TABLE tablename (
ID int,
NewI varchar(255),
etc....
)
首先创建表,然后分别运行select作为select into statement:
SELECT col names
INTO new_table
FROM datasource