将 select 语句的结果插入到 SQL Server 2016 table 或临时 table 中,然后将或 select 插入
Insert result of select statement into a SQL Server 2016 table or temp table to then insert or select into
第一次发帖,如有不妥之处请见谅。
我想知道如何将此结果保存到 SQL Server 2016 table,临时或永久 table。
谢谢。
DECLARE @json nvarchar(max)
SET @json = N'{
"response": [
{
"application": {
"info": {
"dat_id": "010.2018.00036494.001",
"development_type": "Residential - Single new dwelling",
"application_type": "DA",
"last_modified_date": "2018-12-03T11:35:24+11:00",
"description": "Residence, Garage & Colorbond Shed, Demolition of Existing Residence & Tree Removal",
"authority": {
"ref": "http://gemini:82/ApplicationTracker/atdis/1.0",
"name": "AlburyCity"
},
"lodgement_date": "2018-10-26T00:00:00+11:00",
)
[…..]
select * from OPENJSON(@json,'$.response')
with
(
[dat_id] varchar(200) '$.application.info.dat_id',
[development_type] varchar(200) '$.application.info.development_type',
[last_modified_date] varchar(200) '$.application.info.last_modified_date',
[description] varchar(300) '$.application.info.description',
[ref] varchar(200) '$.application.info.authority.ref',
[name] varchar(200) '$.application.info.authority.name'
)
要从 select 结果插入到 table,试试这个方法:
DECLARE @json nvarchar(max)
SET @json = N'{
"response": [
{
"application": {
"info": {
"dat_id": "010.2018.00036494.001",
"development_type": "Residential - Single new dwelling",
"application_type": "DA",
"last_modified_date": "2018-12-03T11:35:24+11:00",
"description": "Residence, Garage & Colorbond Shed, Demolition of Existing Residence & Tree Removal",
"authority": {
"ref": "http://gemini:82/ApplicationTracker/atdis/1.0",
"name": "AlburyCity"
},
"lodgement_date": "2018-10-26T00:00:00+11:00",
)
[…..]
select * into results_from_query from OPENJSON(@json,'$.response')
with
(
[dat_id] varchar(200) '$.application.info.dat_id',
[development_type] varchar(200) '$.application.info.development_type',
[last_modified_date] varchar(200) '$.application.info.last_modified_date',
[description] varchar(300) '$.application.info.description',
[ref] varchar(200) '$.application.info.authority.ref',
[name] varchar(200) '$.application.info.authority.name'
)
结果应该可以在 : results_from_query table
第一次发帖,如有不妥之处请见谅。
我想知道如何将此结果保存到 SQL Server 2016 table,临时或永久 table。
谢谢。
DECLARE @json nvarchar(max)
SET @json = N'{
"response": [
{
"application": {
"info": {
"dat_id": "010.2018.00036494.001",
"development_type": "Residential - Single new dwelling",
"application_type": "DA",
"last_modified_date": "2018-12-03T11:35:24+11:00",
"description": "Residence, Garage & Colorbond Shed, Demolition of Existing Residence & Tree Removal",
"authority": {
"ref": "http://gemini:82/ApplicationTracker/atdis/1.0",
"name": "AlburyCity"
},
"lodgement_date": "2018-10-26T00:00:00+11:00",
)
[…..]
select * from OPENJSON(@json,'$.response')
with
(
[dat_id] varchar(200) '$.application.info.dat_id',
[development_type] varchar(200) '$.application.info.development_type',
[last_modified_date] varchar(200) '$.application.info.last_modified_date',
[description] varchar(300) '$.application.info.description',
[ref] varchar(200) '$.application.info.authority.ref',
[name] varchar(200) '$.application.info.authority.name'
)
要从 select 结果插入到 table,试试这个方法:
DECLARE @json nvarchar(max)
SET @json = N'{
"response": [
{
"application": {
"info": {
"dat_id": "010.2018.00036494.001",
"development_type": "Residential - Single new dwelling",
"application_type": "DA",
"last_modified_date": "2018-12-03T11:35:24+11:00",
"description": "Residence, Garage & Colorbond Shed, Demolition of Existing Residence & Tree Removal",
"authority": {
"ref": "http://gemini:82/ApplicationTracker/atdis/1.0",
"name": "AlburyCity"
},
"lodgement_date": "2018-10-26T00:00:00+11:00",
)
[…..]
select * into results_from_query from OPENJSON(@json,'$.response')
with
(
[dat_id] varchar(200) '$.application.info.dat_id',
[development_type] varchar(200) '$.application.info.development_type',
[last_modified_date] varchar(200) '$.application.info.last_modified_date',
[description] varchar(300) '$.application.info.description',
[ref] varchar(200) '$.application.info.authority.ref',
[name] varchar(200) '$.application.info.authority.name'
)
结果应该可以在 : results_from_query table