如何在 SQL 服务器中的查询创建的 table 中添加一行?
How can I add a row in a table created by a query in SQL Server?
我是 SQL 的初学者。我首先编写了一个创建 table 的查询。有了这个 table 我想添加一些行。我认为使用“insert into”语句是正确的想法,但它没有用。
insert into (
select Element = [Key]
,New = max(case when time_index=1 then value end)
,'Current' = max(case when time_index>=2 then value end)
From (
Select [time_index]
,B.*
From (select * from ifrs17.output_bba where id in (602677,602777)) A
Cross Apply (
Select [Key]
,Value
From OpenJson( (Select A.* For JSON Path,Without_Array_Wrapper ) )
Where [Key] not in ('time_index')
) B
) A
Group By [Key])
values ('acc_test','test', 'test')
我收到此错误消息:
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'select'.
Msg 156, Level 15, State 1, Line 17
Incorrect syntax near the keyword 'values'.
如何向我的 table 添加行?
使用 UNION ALL 连接查询并按元素构造行值:
insert into (
select Element = [Key]
,New = max(case when time_index=1 then value end)
,'Current' = max(case when time_index>=2 then value end)
From (
Select [time_index]
,B.*
From (select * from ifrs17.output_bba where id in (602677,602777)) A
Cross Apply (
Select [Key]
,Value
From OpenJson( (Select A.* For JSON Path,Without_Array_Wrapper ) )
Where [Key] not in ('time_index')
) B
) A
Group By [Key])
UNION
SELECT 'acc_test', 'test', 'test'
我是 SQL 的初学者。我首先编写了一个创建 table 的查询。有了这个 table 我想添加一些行。我认为使用“insert into”语句是正确的想法,但它没有用。
insert into (
select Element = [Key]
,New = max(case when time_index=1 then value end)
,'Current' = max(case when time_index>=2 then value end)
From (
Select [time_index]
,B.*
From (select * from ifrs17.output_bba where id in (602677,602777)) A
Cross Apply (
Select [Key]
,Value
From OpenJson( (Select A.* For JSON Path,Without_Array_Wrapper ) )
Where [Key] not in ('time_index')
) B
) A
Group By [Key])
values ('acc_test','test', 'test')
我收到此错误消息:
Msg 156, Level 15, State 1, Line 2 Incorrect syntax near the keyword 'select'. Msg 156, Level 15, State 1, Line 17 Incorrect syntax near the keyword 'values'.
如何向我的 table 添加行?
使用 UNION ALL 连接查询并按元素构造行值:
insert into (
select Element = [Key]
,New = max(case when time_index=1 then value end)
,'Current' = max(case when time_index>=2 then value end)
From (
Select [time_index]
,B.*
From (select * from ifrs17.output_bba where id in (602677,602777)) A
Cross Apply (
Select [Key]
,Value
From OpenJson( (Select A.* For JSON Path,Without_Array_Wrapper ) )
Where [Key] not in ('time_index')
) B
) A
Group By [Key])
UNION
SELECT 'acc_test', 'test', 'test'