简体   繁体   中英

Json to table in SQL Server 2008

I want to insert below data into a SQL Server table

{ 
    "ITEM_NUMBER":"CSC-ENVM",
    "SHIPPED_DATE":"1995-08-22T00:00:00",
    "STATUS":"Shipped",
    "SOURCE":"Shipment"
},
{ 
    "ITEM_NUMBER":"NP-2R",
    "SHIPPED_DATE":"1995-03-14T18:23:00",
    "STATUS":"Shipped",
    "SOURCE":"Shipment"
}

**ITEM_NUMBER| SHIPPED_DATE | STATUS | SOURCE

CSC-ENVM |1995-08-22T00:00:00| Shipped | Shipment

NP-2R |1995-03-14T18:23:00|Shipped |Shipment**

Just insert into table of a column with Varchar column as mentioned in comments as well

insert into #temp
select '{ 
    "ITEM_NUMBER":"CSC-ENVM",
    "SHIPPED_DATE":"1995-08-22T00:00:00",
    "STATUS":"Shipped",
    "SOURCE":"Shipment"
},
{ 
    "ITEM_NUMBER":"NP-2R",
    "SHIPPED_DATE":"1995-03-14T18:23:00",
    "STATUS":"Shipped",
    "SOURCE":"Shipment"
}'

In SQL 2008,you also can read this JSON data using ParseJson function created by Phil Factor.you can read on about that here...

Consuming JSON Strings in SQL Server

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM