andrew4582

fnPaddLeadingZeros

Mar 30th, 2012
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.08 KB | None | 0 0
  1.  
  2.  
  3. /****** Object:  UserDefinedFunction [dbo].[fnPaddLeadingZeros]    Script Date: 03/30/2012 13:04:52 ******/
  4. IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fnPaddLeadingZeros]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
  5. DROP FUNCTION [dbo].[fnPaddLeadingZeros]
  6. GO
  7.  
  8.  
  9. /****** Object:  UserDefinedFunction [dbo].[fnPaddLeadingZeros]    Script Date: 03/30/2012 13:04:52 ******/
  10. SET ANSI_NULLS ON
  11. GO
  12.  
  13. SET QUOTED_IDENTIFIER ON
  14. GO
  15.  
  16. CREATE FUNCTION [dbo].[fnPaddLeadingZeros](
  17. @Value int
  18. )
  19. RETURNS varchar(8)
  20. WITH SCHEMABINDING
  21. AS
  22. BEGIN
  23. DECLARE @ReturnValue varchar(8);
  24. SET @ReturnValue = CONVERT(varchar(8), @Value);
  25. SET @ReturnValue = REPLICATE('0', 8 - DATALENGTH(@ReturnValue)) + @ReturnValue;
  26. RETURN (@ReturnValue);
  27. END;
  28.  
  29. GO
  30.  
  31. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Input parameter for the scalar function fnPaddLeadingZeros. Enter a valid integer.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'FUNCTION',@level1name=N'fnPaddLeadingZeros', @level2type=N'PARAMETER',@level2name=N'@Value'
  32. GO
Advertisement
Add Comment
Please, Sign In to add comment