CHECKSUM and OPTION(RECOMPILE)


Working with CHECKSUM
functions, I encountered a situation
when the result of the
CHECKSUM function is
effected by OPTION(RECOMPILE)


Please see following example:




DECLARE @a VARCHAR(5),@b VARCHAR(5)
SET @a='a'
SET @b='b'

SELECT CHECKSUM(@a,@b) as Result






SELECT CHECKSUM(@b,@a) as Result

 



SELECT CHECKSUM(@a,@b) as Result
OPTION(RECOMPILE)




As you can see the result of CHECKSUM(@a,@b) without recompile
and with recompile is different, when using option(recompile)
we see that SQL Server change the order of the variables.

Do you know why?
If yes, Please leave comments.