I'm inserting data into a table using data from a JSON-file. I want to set a bit column isMain to 1 at the same time. I tried so by using the code below, but it throws an error saying it's incorrect syntax. How could I achieve this?
INSERT INTO Company
(
OrganizationNumber,
Name
IsMain
)
SELECT company.*
FROM OPENROWSET(BULK '<path to json-file>', SINGLE_NCLOB) AS j
CROSS APPLY OPENJSON(BulkColumn)
WITH (
organizationNumber NVARCHAR(255) '$.organizationNumber',
name NVARCHAR(255) '$.name',
isMain BIT '1'
)
AS company;
IsMainin yourSELECT, not yourOPENJSON'sWITHclause. (SELECT organizationNumber, [name], 1 FROM...)