Does anybody knows how to get @odata.etag value from a JSON into a SQL Server table? Many thanks!
JSON string:
{
"@odata.context": "https://mycompany.com/Tenant/ODataV4/$metadata#Company('mycompany')/ServiceHeader/$entity",
"@odata.etag":"W/"JzQ0O0NLZ0lhMkdDdkw3ZU1PbUx6M1M5V1Y4OUtUZUI5OXZOUCtjM2FRZmQ1N0E9MTswMDsn"",
"Document_Type": "Order",
"No": "1234",
"Customer_No": "1234",
"Your_Reference": "",
"Payment_Terms_Code": "01",
"Name": "Company ABC",
"Contact_No": "4567",
"Status": "Pending",
"Release_Status": "Open",
"Description": "",
"Contract_No": "",
"Service_Order_Type": "",
"Last_Modified_Date_Time": "2023-06-30T14:40:39.307Z",
"FBID": "",
"FBWorkOrderNo": "",
"Bill_to_Customer_No": "1234"
}
I have tried to use this code:
SELECT
TableA.etag
FROM
OPENJSON((SELECT * FROM @json))
WITH (
etag nvarchar(300) '[email protected]'
) AS TableA
I get this error:
JSON path is not properly formatted. Unexpected character ‘@’ is found at position 2.
2
Answers
Best solution from Thom A. Many thanks.
You are extracting the
@odata.etag
value from the JSON string using theJSON_VALUE
function. However, in your case, the error occurs because theOPENJSON
function expects a JSON expression, not a table variable.