'INTERVAL' is not a recognized ODBC date/time extension option

All we need is an easy explanation of the problem, so here it is.

According to this docs on Interval Literals, this should be a valid INTERVAL,

SELECT {INTERVAL '326' YEAR(4)};

But when I try that on dbfiddle, I get,

Msg 155 Level 15 State 1 Line 1
'INTERVAL' is not a recognized ODBC date/time extension option.

Is that error a fault of dbfiddle, SQL Server, or the ODBC transport layer not knowing how to textify a interval — I tried adding it to a date, hoping that would produce a date but alas same error?

If I try it without the {}, I get

Msg 102 Level 15 State 1 Line 1
Incorrect syntax near 'YEAR'.

Interval Literals

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

Looks like a dbfiddle isn’t using ODBC. The “‘INTERVAL’ is not a recognized” error will be returned by SqlClient.

SqlClient looks like it supports ODBC escape sequences that have corresponding SQL Server data types but I can’t find this behavior documented. The error occurs because there is currently no INTERVAL type in Microsoft SQL Server.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply