Here is the section of code that has the logic. Everything else is just Messages for the user.
ClearErrors
ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Microsoft SQL Server\SQLEXPRESS\MSSQLServer\CurrentVersion" "CurrentVersion"
IfErrors SQLServerNotFound SQLServerFound1
SQLServerFound1:
StrCpy $1 $0 2
StrCmp $1 "10" SQLServer2008Found SQLServerFound2
SQLServerFound2:
StrCpy $1 $0 2
StrCmp $1 "11" SQLServer2012Found SQLServerVersionError
SQLServer2008Found:
Push $0
Push "."
Call StrTok ;For an example string of "10.50.6000", "10" and "50.6000" now on stack
Pop $2
Push "."
Call StrTok ;"50" and "6000" now on stack
Pop $2
Pop $3
${VersionCompare} $3 6000 $R0
${If} $R0 == "0"
Goto ExitCheckMinSQLVersionNonAbort
${ElseIf} $R0 == "1"
Goto ExitCheckMinSQLVersionNonAbort
${ElseIf} $R0 == "2"
!ifndef SQLVersion
!define SQLVersion "SQLServer 2008 R2 version of SP3 10.50.6000"
!endif
Goto SQLServerVersionError
${EndIf}
Goto ExitCheckMinSQLVersionNonAbort
SQLServer2012Found:
Push $0
Push "."
Call StrTok ;For an example string of "11.0.6020", "11" and "0.6020" now on stack
Pop $2
Push "."
Call StrTok ;"0" and "6020" now on stack
Pop $2
Pop $3
${VersionCompare} $3 2100 $R0
${If} $R0 == "0"
Goto ExitCheckMinSQLVersionNonAbort
${ElseIf} $R0 == "1"
Goto ExitCheckMinSQLVersionNonAbort
${ElseIf} $R0 == "2"
!ifndef SQLVersion
!define SQLVersion "SQLServer 2012 Version of SP3 11.0.6020"
!endif
Goto SQLServerVersionError
${EndIf}
Goto ExitCheckMinSQLVersionNonAbort