E
E
embiid2020-04-20 20:31:21
SQL
embiid, 2020-04-20 20:31:21

How to move tuples to another table?

Hello!

I parsed the data, and wrote the data to a json file, after which I transferred this data to a table:

select Name, CapitalCity, LargestCity, Admission, Population from OpenJson('
[
  {
    "name": "Alabama",
    "capitalCity": "Montgomery",
    "largestCity": "Birmingham",
    "admission": "Dec 14, 1819",
    "population": "4,903,185"
  }, ...
')
with (
  Name nvarchar(20) '$.name',
  CapitalCity nvarchar(30) '$.capitalCity',
  LargestCity nvarchar(20) '$.largestCity',
  Admission nvarchar(20) '$.admission',
  Population nvarchar(20) '$.population'
)


Created a table:
create table State(
  ID int not null,
  Name nvarchar(20) not null,
  CapitalCity nvarchar(30) not null,
  LargestCity nvarchar(30) null,
  Admission nvarchar(20) null,
  Population nvarchar(20) not null,

  primary key(ID),
)


And how can I now transfer the converted json data to the table that is in the database?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
idShura, 2020-04-21
@embiid

INSERT INTO MyTABLE (Name, CapitalCity, LargestCity, Admission, Population)
select Name, CapitalCity, LargestCity, Admission, Population from OpenJson('
[
  {
    "name": "Alabama",
    "capitalCity": "Montgomery",
    "largestCity": "Birmingham",
    "admission": "Dec 14, 1819",
    "population": "4,903,185"
  }, ...
')
with (
  Name nvarchar(20) '$.name',
  CapitalCity nvarchar(30) '$.capitalCity',
  LargestCity nvarchar(20) '$.largestCity',
  Admission nvarchar(20) '$.admission',
  Population nvarchar(20) '$.population'
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question