andrew4582

fnFormatNumber

Mar 30th, 2012
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.13 KB | None | 0 0
  1.  
  2.  
  3. /****** Object:  UserDefinedFunction [dbo].[fnFormatNumber]    Script Date: 03/30/2012 13:24:03 ******/
  4. IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fnFormatNumber]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
  5. DROP FUNCTION [dbo].[fnFormatNumber]
  6. GO
  7.  
  8.  
  9. /****** Object:  UserDefinedFunction [dbo].[fnFormatNumber]    Script Date: 03/30/2012 13:24:03 ******/
  10. SET ANSI_NULLS ON
  11. GO
  12.  
  13. SET QUOTED_IDENTIFIER ON
  14. GO
  15.  
  16. -- =============================================
  17. -- Author:      Andrew
  18. -- Create date: Friday March 30,2012 1:07 PM
  19. -- Description: Formats a number with commas
  20. -- =============================================
  21. CREATE FUNCTION [dbo].[fnFormatNumber]
  22. (
  23.     -- Add the parameters for the function here
  24.     @number int
  25. )
  26. RETURNS nvarchar(50)
  27. AS
  28. BEGIN
  29.     -- Declare the return variable here
  30.     DECLARE @Result nvarchar(50)
  31.  
  32.     -- Add the T-SQL statements to compute the return value here
  33.     SELECT @Result = REPLACE(CONVERT(varchar(20), (CAST(@number AS money)), 1), '.00', '')
  34.  
  35.     -- Return the result of the function
  36.     RETURN @Result
  37.  
  38. END
  39.  
  40. GO
  41. SELECT [dbo].[fnFormatNumber] (123456)
Advertisement
Add Comment
Please, Sign In to add comment