3

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**

2
  • SQL Server 2008 has no direct, built-in support for JSON. You need to use some other tool - a language like C#, Ruby, PHP or whatever you're comfortable with - to read this JSON, convert it to objects, and then insert those objects and their values into SQL Server Commented Oct 6, 2016 at 10:30
  • Just use a regular INSERT statement, targeting a varchar/nvarchar column of the needed maximum length. Commented Oct 6, 2016 at 10:34

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.