Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /****** Object: UserDefinedFunction [dbo].[fnFormatNumber] Script Date: 03/30/2012 13:24:03 ******/
- 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'))
- DROP FUNCTION [dbo].[fnFormatNumber]
- GO
- /****** Object: UserDefinedFunction [dbo].[fnFormatNumber] Script Date: 03/30/2012 13:24:03 ******/
- SET ANSI_NULLS ON
- GO
- SET QUOTED_IDENTIFIER ON
- GO
- -- =============================================
- -- Author: Andrew
- -- Create date: Friday March 30,2012 1:07 PM
- -- Description: Formats a number with commas
- -- =============================================
- CREATE FUNCTION [dbo].[fnFormatNumber]
- (
- -- Add the parameters for the function here
- @number int
- )
- RETURNS nvarchar(50)
- AS
- BEGIN
- -- Declare the return variable here
- DECLARE @Result nvarchar(50)
- -- Add the T-SQL statements to compute the return value here
- SELECT @Result = REPLACE(CONVERT(varchar(20), (CAST(@number AS money)), 1), '.00', '')
- -- Return the result of the function
- RETURN @Result
- END
- GO
- SELECT [dbo].[fnFormatNumber] (123456)
Advertisement
Add Comment
Please, Sign In to add comment