Abundant Technologies - IT Consulting Experts

 Source Code Library

 Code Details

 
/****** Object: User Defined Function dbo.fCurrency Script Date: 2/16/2004 10:51:04 AM ******/ CREATE FUNCTION fCurrency (@Value money) RETURNS varchar(50) AS BEGIN DECLARE @OriginalValue as varchar(50) DECLARE @Cents as varchar(2) DECLARE @Dollars as varchar(50) DECLARE @Currency as varchar(50) DECLARE @nDx as int DECLARE @nDx2 as int IF @Value Is Null SELECT @Currency = '$0.00' ELSE BEGIN SELECT @OriginalValue = CONVERT(DECIMAL(19, 2), @Value) SELECT @Cents = RIGHT(@OriginalValue,2) SELECT @nDx = LEN(@OriginalValue) - 3 SELECT @Dollars = LEFT(@OriginalValue,@nDx) SELECT @Currency = '' WHILE @nDX > 0 BEGIN SELECT @nDX2 = @nDX -3 SELECT @Currency = SUBSTRING(@Dollars,@nDX2+1,3) + ',' + @Currency SELECT @nDX = @nDX -3 END SELECT @Currency = '$' + SUBSTRING(@Currency,1,LEN(@Currency)-1) + '.' + @Cents END RETURN ( @Currency ) END GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO

Mail To: info@3pc.com