Fix the “Operand type clash” Error when using GENERATE_SERIES() in SQL Server

If you’re getting the “Operand type clash” error when using the GENERATE_SERIES() function in SQL Server, it’s probably because your arguments aren’t of the same type.

The arguments/operands we provide to the GENERATE_SERIES() function/relational operator need to be of the same type. For example, if we pass an integer as the first argument, then the other arguments must also be an integer.

This error may also come with another error which tells us that the input parameters must be of the same type.

To fix, make sure all arguments are of the same type.

Example of Error

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

SELECT value 
FROM GENERATE_SERIES(0, 5, 1.5);

Result

Msg 206, Level 16, State 2, Server 2744dc1ca22c, Line 1
Operand type clash: int is incompatible with void type
Msg 206, Level 16, State 2, Server 2744dc1ca22c, Line 1
Operand type clash: int is incompatible with void type
Msg 206, Level 16, State 2, Server 2744dc1ca22c, Line 1
Operand type clash: numeric is incompatible with void type
Msg 5373, Level 16, State 2, Server 2744dc1ca22c, Line 1
All the input parameters should be of the same type. Supported types are tinyint, smallint, int, bigint, decimal and numeric.

This is quite a large error message considering the minor error in the code.

My only mistake was that I passed mismatching argument types. Specifically, the first two arguments are int types, and the third one is numeric.

We ended up getting error message 206 for each of the arguments, and then error message 5373 as an overall error message that explains that all input parameters should be of the same type.

We’d get the same error if there was a mismatch with the first two arguments. Both the first and second argument must be of the same type.

Solution

To fix this issue, simply ensure that all arguments are of the same type.

Therefore, one way to fix the above example is by making the first two arguments numeric:

SELECT value 
FROM GENERATE_SERIES(0.0, 5.0, 1.5);

Result

value
-----
   .0
  1.5
  3.0
  4.5

By changing the first two arguments to the numeric type, they can now be incremented by the numeric amount specified at the third argument.

Another way to do it is to change the last argument to an integer (in order to match the first two arguments):

SELECT value 
FROM GENERATE_SERIES(0, 5, 1);

Result

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

However, this removed our ability to increment by fractions. In this example I had to change 1.5 to 1 in order for this to work, which changed the values in the resulting series.