Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE FUNCTION def.Digits (@FunctionInput INT)
- RETURNS INTEGER
- AS
- BEGIN
- DECLARE @Dropoff VARCHAR(MAX) = CAST(@FunctionInput AS VARCHAR(MAX))
- DECLARE @Final VARCHAR(MAX) = @Dropoff
- DECLARE @DropIncrement INT = 1
- DECLARE @StepIncrement INT = 0
- WHILE LEN(@Final) <> 1
- BEGIN
- SET @DropIncrement = 1
- WHILE LEN(@Dropoff) <> 0
- BEGIN
- SET @DropIncrement = @DropIncrement * LEFT(@Dropoff,1)
- SET @Dropoff = LTRIM(@Dropoff,1)
- END
- SET @Final = CAST(@DropIncrement AS VARCHAR(MAX))
- SET @Dropoff = @Final
- SET @StepIncrement = @StepIncrement + 1
- END
- RETURN (@StepIncrement)
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement