0

I have this query:

INSERT INTO [clients] ([FirstName], [LastName])
    SELECT FirstName, LastName
    FROM OPENJSON(@JsonRequest)
    WITH
        (FirstName NVARCHAR(50),
         LastName NVARCHAR(50)
        )

Now I want to fill two more columns with ONE external parameter - @ID and one with a SQL Server function - CURRENT_TIMESTAMP. I can't figure out how to build the query

INSERT INTO [clients] ([FirstName], [LastName], [createdDate], [ID])
    SELECT FirstName, LastName
    FROM OPENJSON(@JsonRequest)
    WITH 
        (FirstName NVARCHAR(50),
         LastName NVARCHAR(50)
        ),
        CURRENT_TIMESTAMP,
        @ID

But this is not working...

1 Answer 1

3

I think you just need to move the columns to the select part

INSERT INTO [clients] ([FirstName], [LastName], [createdDate], [ID])
    SELECT
        FirstName, LastName, CURRENT_TIMESTAMP, @ID
    FROM OPENJSON(@JsonRequest)
    WITH (
            FirstName NVARCHAR(50),
            LastName NVARCHAR(50)
         )
Sign up to request clarification or add additional context in comments.

1 Comment

Its OK now. Thank you!

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.