title: T-SQL Recursive Division
body: <p>How do I perform recursive division in SQL?</p>
  
  <p>I know the basic premise is</p>
  
  <pre><code>declare @i = 0
  declare @testValue bigint = FLOOR(@num/@dem)
  while @testValue&gt;0
  begin
     set @num = @num - @testValue*@dem
     set @testValue = FLOOR(@num/@dem)
     set @i = @i + 1
  end
  </code></pre>
  
  <p>, but I do not know how to do this in an efficient manner.</p>