to_decimal.sql 532 B

123456789101112131415161718192021222324252627282930
  1. SET QUOTED_IDENTIFIER ON
  2. GO
  3. SET ANSI_NULLS ON
  4. GO
  5. CREATE FUNCTION [dbo].[to_decimal] (@d varchar(255))
  6. RETURNS decimal(28,8)
  7. with execute as CALLER
  8. AS
  9. BEGIN
  10. declare @to_decimal decimal(28,8);
  11. if @d is null
  12. return 0.0;
  13. set @d = replace(@d, '"', '');
  14. if @d = ''
  15. return 0.0
  16. set @d = replace(@d, ',', '.');
  17. if isnumeric(@d) = 0
  18. return 0.0
  19. set @to_decimal = convert(decimal(28,8), convert(float, @d));
  20. return (@to_decimal);
  21. END
  22. GO
  23. SET QUOTED_IDENTIFIER OFF
  24. GO
  25. SET ANSI_NULLS OFF
  26. GO
  27. GO