execution modulo on a large number in t-sql

sql, sql-server, t-sql

Solution

If it is too big for `bigint` you can use `NUMERIC(38,0)`

DECLARE @Num VARCHAR(38) = '271011240311350356232122'
SELECT CAST(@Num AS NUMERIC(38,0)) % 97

Problem

I need to calculate the remainder of one number divided by another. for instance with these numbers: 271011240311350356232122 % 97 When I just want to do that in a sql statement, it works like a charm: select 271011240311350356232122 % 97; But when I have that large number in a varchar variable, I can't seem to get the job done. I can't convert it into a int or even bigint, because it's too large. I can't convert it into a real because you can't use the modulo operator on a real number. Any ideas...?

Original source