관리 메뉴

안까먹을라고 쓰는 블로그

[MSSQL] C#의 PadLeft, PadRight 함수 구현 본문

DataBase/MS SQL

[MSSQL] C#의 PadLeft, PadRight 함수 구현

YawnsDuzin 2016. 5. 31. 14:25

 

반응형

■ MSSQL 의 PadLeft, PadRight 함수구현

USE [CJ_Sugar]
GO
/****** Object:  UserDefinedFunction [dbo].[uf_PadLeft]    Script Date: 05/31/2016 14:20:55 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER FUNCTION [dbo].[uf_PadLeft] (@expr varchar(255), @totalWidth int, @paddingChar varchar(255))  
RETURNS varchar(255) AS  

BEGIN 
	return isnull(replicate(@paddingChar, @totalWidth - len(@expr)), '') + @expr
END


USE [CJ_Sugar]
GO
/****** Object:  UserDefinedFunction [dbo].[uf_PadRight]    Script Date: 05/31/2016 14:20:56 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER FUNCTION [dbo].[uf_PadRight] (@expr varchar(255), @totalWidth int, @paddingChar varchar(255))  
RETURNS varchar(255) AS  

BEGIN 
	return @expr + isnull(replicate(@paddingChar, @totalWidth - len(@expr)), '')
END


■ MSSQL 의 PadLeft, PadRight 함수사용

select dbo.uf_PadLeft('park', 10, '0')
-- 결과 : 000000park

select dbo.uf_PadRight('park', 10, '0')
-- 결과 : park000000


[ 출처 ] http://blog.naver.com/ssayagain/90020486135


반응형
Comments