Ontario Health Card mod 10 validation
This is based on the Luhn-algorithm, see this answer.

Those solutions are generic, i.e. for any input length, but for a specific length string I prefer a brute-force approach, no variables/loops/etc., just cut&amp;paste&amp;modify:

select -- luhn check digit
   (10-
     ( -- sum of all digits after doubling the odd digits
        Substring(inputString, 1,1)*2 % 10
      + Substring(inputString, 1,1)*2 / 10
      + Substring(inputString, 2,1)
      + Substring(inputString, 3,1)*2 % 10
      + Substring(inputString, 3,1)*2 / 10
      + Substring(inputString, 4,1)
      + Substring(inputString, 5,1)*2 % 10
      + Substring(inputString, 5,1)*2 / 10
      + Substring(inputString, 6,1)
      + Substring(inputString, 7,1)*2 % 10
      + Substring(inputString, 7,1)*2 / 10
      + Substring(inputString, 8,1)
      + Substring(inputString, 9,1)*2 % 10
      + Substring(inputString, 9,1)*2 / 10
     ) % 10 -- subtract the last digit
   ) % 10   -- in case last digit is a zero: 10 -&gt; 0


Put it in a CASE to get 0/1:

case when previous calculation = Substring(inputString, 10,1)
     then 1 
     else 0
end