티스토리 뷰

Database

[MSSQL]LPAD,RPAD,프로시저

애플자라 2012. 3. 20. 11:49
반응형

CREATE PROCEDURE [dbo].[AP_getcustcode] AS
BEGIN
 RETURN SELECT dbo.lpad(
   ( select max(cust_code)+1 from customerinfo ), 15, '0' )

==============================================

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE   FUNCTION [dbo].[GetCSContactSeqNew]  ( @CustCode char(15) )
RETURNS char(3) AS 
BEGIN
declare  @id char(3)
 SELECT @id = dbo.LPAD( ISNULL(MAX(CSCON_CODE)+1,1), 3, '0') FROM CSCONTACT WHERE CUST_CODE = @CustCode
 IF @id = NULL
  BEGIN
   SELECT @id = dbo.LPAD( '1', 3, '0')
  END
 RETURN @id
END

dbo.GetCSContactSeqNew('${CUST_CODE}')

==============================================

SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE FUNCTION [dbo].[LPAD]
   ( @sSrcValue nvarchar(20), @nSize int, @sChar nvarchar(2)) 
RETURNS nvarchar(100)  AS 
BEGIN
RETURN (ISNULL( REPLICATE(@sChar, @nSize-len(@sSrcValue))+@sSrcValue, substring(@sSrcValue,len(@sSrcValue)-@nSize+1,len(@sSrcValue) )   ))
END

==============================================

SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE FUNCTION [dbo].[RPAD]
   ( @sSrcValue nvarchar(20), @nSize int, @sChar nvarchar(2)) 
RETURNS nvarchar(100)  AS 
BEGIN
RETURN (@sSrcValue+REPLICATE(@sChar, @nSize-len(@sSrcValue)))
END

==============================================


반응형
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
글 보관함