OPENJSON “Incorrect syntax near the keyword ‘with’.” in SQL Server (SOLVED)

If you’re trying to run some OPENJSON() code in SQL Server, but you’re getting error Msg 319, Level 15 “Incorrect syntax near the keyword ‘with'”, one possibility is that you really do have a syntax error.

But if you’ve check and double checked, and you’re convinced there’s no syntax error, it could actually be that the error is a side effect of having the wrong database compatibility level.

Normally you’d get error Msg 208, Level 16 “Invalid object name ‘OPENJSON’.” when using a database compatibility level of lower than 130, but in some cases, SQL Server finds a problem with the WITH clause first.

Continue reading

How to Fix “Invalid object name ‘OPENJSON’.” in SQL Server

If you encounter error Msg 208, Level 16 “Invalid object name ‘OPENJSON’.”, you are probably trying to use the OPENJSON() function on a database with a compatibility level of less than 130.

OPENJSON() is only available under compatibility level 130 or higher.

To fix this, either increase the compatibility level of your database to 130 or higher, or change to a database that already has the appropriate compatibility level.

Continue reading

How to Use the BETWEEN Operator in SQL Server

The SQL Server BETWEEN operator allows you to test between a range of values in your queries. For example, you could test that a value is between two numbers.

The BETWEEN operator is inclusive, meaning that it includes the values that you specify within the range. That is, it includes values that are greater than or equal to the lower value, and values that are less than or equal to the higher value. Therefore it’s like using >= and <=.

Continue reading

SQL Server Error 7222: “Only a SQL Server provider is allowed on this instance”

I was trying to set up a up a linked server from SQL Server to PostgreSQL when I got error Msg 7222, Level 16 “Only a SQL Server provider is allowed on this instance”.

The message is reasonably self explanatory, but it still didn’t tell me what it was about my instance that prevented it from being allowed.

It didn’t take long to find out.

Continue reading