mo.notono.us

Tuesday, July 25, 2006

A Fix() Function in T-SQL

Rob Farley did a nice writeup on how to create A Fix() Function in T-SQL, using TDD concepts to boot.

Final code:

create function dbo.fix(@num float, @digits int) returns float as
begin
  declare @res float
  select @res = case 
    when @num > 0 
      then round(@num,@digits-1-floor(log10(@num))) 
      else round(@num,@digits-1-floor(log10(-@num))) 
    end
  return (@res)
end

Technorati Tags: , ,

Labels:

0 Comments:

Post a Comment

<< Home