我将 json 文件插入到我的 table 中,但如何将日期也放入我的 table 中?

I inserted the json file into my table, but how do i put in the date into my table as well?

这是我的 table 的结果。我剩下要做的就是插入当前 加载日期中的日期:

我一直在尝试添加 JSON 文件中的数据加载到 table 中的日期,但不知道正确的语法。有什么帮助吗? :)

您可以使用 GETDATE(),是实际的日期时间。

sysdatetimeofffset() 应该做你想做的。排列列,类似下面的内容应该可以工作:

select *, sysdatetimeoffset() from
openjson(@PersonDetails, <etc>

取自您在另一个答案下方的评论:

That didn't quite work this was the error "Column name or number of supplied values does not match table definition."

您遇到的问题与

有关
insert into main.jsontable
select * from...

您永远不应依赖列顺序。您要插入的列和您要读取的列必须匹配。最坏的情况是巧合错配。

关于bad habits to kick: SELECT with *

将此更改为

insert into main.jsontable(name, surname, email, ...more columns...)
select <list your JSON "columns" here> 
from...

然后最后一步是将 dateloaded 添加到此:

insert into main.jsontable(dateloaded, name, surname, email, ...more columns...)
select SYSUTCDATETIME(), <list your JSON "columns" here> 
from...

更新

你已经被告知,张贴图片是要避免的事情。很难从那里阅读,但你似乎正试图在这里解决这个问题

with(
[dateloaded] datetimeoffset,
[name] ...

派生列 永远不会获得任何值,因为您没有从 JSON.

中读取它