Fix “‘GENERATE_SERIES’ is not a recognized built-in function name” in SQL Server

If you’re getting an error that reads “‘GENERATE_SERIES’ is not a recognized built-in function name” in SQL Server, it could be that you’re calling GENERATE_SERIES() in the wrong context.

In SQL Server, GENERATE_SERIES() is a relational operator that returns a series of values from a given start and stop point.

When we call GENERATE_SERIES() in a SQL query, we don’t include it in the SELECT list, like we would with many SQL functions. Instead, we reference it in the FROM clause, like we would reference a table.

So if you’re getting the above error, it could be that you’re inadvertently making this mistake. To fix, be sure to call GENERATE_SERIES() in the correct context.

You could also get a similar (but different) error if you try to call GENERATE_SERIES() in a version of SQL Server that doesn’t support this function. GENERATE_SERIES() was introduced in SQL Server 2022, and so if you’re using an earlier version of SQL Server, then you might receive a similar error (depending on the context you try to call it under).

Example of Error

Here’s an example of code that produces the error:

SELECT GENERATE_SERIES( 1, 5 );

Result:

Msg 195, Level 15, State 10, Server c257fce1f7b0, Line 1
'GENERATE_SERIES' is not a recognized built-in function name.

I ran that code in SQL Server 2022. The error tells me that GENERATE_SERIES() is not a recognised built-in function name, even though this function is definitely supported in SQL Server 2022.

I got the error because I used the function in the wrong context. I called it in the SELECT list, but I should have called it in the FROM clause (as if it’s a table or view).

Solution

To fix the above issue, all we need to do is move the function to the FROM clause:

SELECT value FROM GENERATE_SERIES( 1, 5 );

Result:

value      
-----------
          1
          2
          3
          4
          5

The function returns a single-column table containing the sequence of values. The name of the column is value, and so that’s why I referenced value in my SELECT list.