Fix “Procedure or function GENERATE_SERIES has too many arguments specified” in SQL Server

If you’re getting error 8144 with a message that reads “Procedure or function GENERATE_SERIES has too many arguments specified” in SQL Server, it’s because you’re passing too many arguments to the GENERATE_SERIES() function.

The GENERATE_SERIES() function/relational operator accepts a minimum of two arguments, and a maximum of three (at least, this is the case at the time of writing).

So to fix this error, be sure to provide either two arguments or three when using the GENERATE_SERIES() function.

Example of Error

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

SELECT * FROM GENERATE_SERIES( 1, 3, 1, 2 );

Result

Msg 8144, Level 16, State 3, Server 36cbed1b7677, Line 1
Procedure or function GENERATE_SERIES has too many arguments specified.

The error message is quite clear; too many arguments were specified. I passed four arguments, but the function accepts a maximum of three.

Solution

To fix this issue, simply remove the unnecessary argument/s:

SELECT * FROM GENERATE_SERIES( 1, 3, 1 );

Result

value      
-----------
          1
          2
          3

The first argument specifies the start point, the second specifies the end point, and the third argument specifies the step amount (i.e. the amount that the series will increment by).

It’s possible to omit the third argument. If we do, it uses the default step amount:

SELECT * FROM GENERATE_SERIES( 1, 3 );

Result

value      
-----------
          1
          2
          3

In this case, the default step amount was 1.

The default step amount is either 1 or -1 depending on the first two arguments:

  • When the start point is lower than the stop point, the default step is 1
  • When the start point is higher than the stop point, the default step is -1

The following example has a default step of -1:

SELECT * FROM GENERATE_SERIES( 3, 1 );

Result

value      
-----------
          3
          2
          1

SQL Server was smart enough to know that we were creating a decrementing series, and so it made the default step amount -1.