[英]how to add row in a table created by a query in sql server?
我從 SQL 開始。 我首先編寫了一個創建表的查詢。 有了這張表,我想添加一些行。 我認為使用“插入”語句是正確的想法,但它不起作用。
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')
我收到此錯誤消息:
消息 156,第 15 級,State 1,第 2 行
關鍵字“select”附近的語法不正確。
消息 156,第 15 級,State 1,第 17 行
關鍵字“值”附近的語法不正確。
你能告訴我如何在我的表格中添加行嗎?
使用 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'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.