Advertisement
Piexplode

Untitled

Mar 21st, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.57 KB | None | 0 0
  1. CREATE FUNCTION def.Digits (@FunctionInput INT)
  2. RETURNS INTEGER
  3. AS
  4. BEGIN
  5. DECLARE @Dropoff VARCHAR(MAX) = CAST(@FunctionInput AS VARCHAR(MAX))
  6. DECLARE @Final VARCHAR(MAX) = @Dropoff
  7. DECLARE @DropIncrement INT = 1
  8. DECLARE @StepIncrement INT = 0
  9. WHILE LEN(@Final) <> 1
  10. BEGIN
  11. SET @DropIncrement = 1
  12.  
  13. WHILE LEN(@Dropoff) <> 0
  14. BEGIN
  15. SET @DropIncrement = @DropIncrement * LEFT(@Dropoff,1)
  16. SET @Dropoff = LTRIM(@Dropoff,1)
  17. END
  18.  
  19. SET @Final = CAST(@DropIncrement AS VARCHAR(MAX))
  20. SET @Dropoff = @Final
  21. SET @StepIncrement = @StepIncrement + 1
  22.  
  23. END
  24. RETURN (@StepIncrement)
  25. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement