¾È±Ô °øºÎ¹æ

MS-SQL > User Function - ÃÊ°£°Ý, ºÐ°£°Ý, ½Ã°£°£°Ý, ÀÏ°£°Ý Ç¥ÇöÇϱâ (³¯Â¥ºñ±³ÈÄ)

µî·ÏÀÏ : 2017-07-03 19:18 Á¶È¸¼ö : 52,519

ÃÊ°£°Ý, ºÐ°£°Ý, ½Ã°£°£°Ý, ÀÏ°£°Ý Ç¥ÇöÇϱâ (³¯Â¥ºñ±³ÈÄ)


1) ÇöÀ纸´Ù °ú°ÅÀÇ ÁöÁ¤µÈ ÀÏÀÚ¿ÍÀÇ Â÷ Ç¥Çö - µÎ ÀÏÀÚ°£ Â÷°¡ ´ÙÀ½°ú °°Àº ´ÜÀ§ À϶§
- ÃÊ ´ÜÀ§ : ~ÃÊ ÀüÀ¸·Î Ç¥Çö
- ºÐ ´ÜÀ§ : ~ºÐ ÀüÀ¸·Î Ç¥Çö
- ½Ã°£ ´ÜÀ§ : ~½Ã°£ ÀüÀ¸·Î Ç¥Çö
- ±× ¿Ü ÇÏ·ç°¡ ³Ñ¾î°¥ ¶§ : ~ÀÏ ÀüÀ¸·Î Ç¥Çö



»ç¿ëÀÚ ÇÔ¼ö¿Í ³¯Â¥ÇÔ¼ö(DATEDIFF)¸¦ ÀÌ¿ëÇÏ¿© ÃÊ°£°Ý, ºÐ°£°Ý, ½Ã°£°£°Ý, ÀÏ°£°Ý Ç¥ÇöÇØ º¼ ¼ö ÀÖ´Ù.

¾Æ·¡Ã³·³ »ç¿ëÀÚ ÇÔ¼ö¸¦ ¸¸µç´Ù.
 
CREATE FUNCTION     [dbo].[fn_RegDate_Display](  
		        @iDate          DATETIME  
	) 
		RETURNS VARCHAR(20)  
		AS  
			BEGIN  
				DECLARE @wDisplay       VARCHAR(20)  
				SELECT  @wDisplay       = ''  
			  
				IF  DATEDIFF(ss,@iDate,GETDATE())   < 60   
				   SELECT  @wDisplay   = CAST(DATEDIFF(ss,@iDate,GETDATE()) AS VARCHAR) + 'ÃÊÀü'  
			   ELSE IF DATEDIFF(mi,@iDate,GETDATE())   < 60   
				   SELECT  @wDisplay   = CAST(DATEDIFF(mi,@iDate,GETDATE()) AS VARCHAR) + 'ºÐÀü'  
			   ELSE IF DATEDIFF(hh,@iDate,GETDATE())   < 24   
				   SELECT  @wDisplay   = CAST(DATEDIFF(hh,@iDate,GETDATE()) AS VARCHAR) + '½Ã°£Àü'  
			   ELSE   
				   SELECT  @wDisplay       = CONVERT(VARCHAR(10),@iDate,120)         
			   RETURN (@wDisplay)  
			END  
 
select *, dbo.fn_RegDate_Display(writeday) from t_db



¾î·ÆÁö ¾Ê°Ô ¸¸µé ¼ö ÀÖ´Ù.
 
¡Ø Ȥ½Ã µµ¿òÀÌ µÇ¼Ì´Ù¸é ´ñ±Û¿¡ ÇѸ¶µð ³²°ÜÁÖ¼¼¿ä!
ÀÛ¼ºÀÚ   ºñ¹Ð¹øÈ£
ÀÚµ¿±Û ¹æÁö     (ÀÚµ¿±Û ¹æÁö ±â´ÉÀÔ´Ï´Ù.)
³»¿ë   ´ñ±Û´Þ±â 
À̸ÞÀÏ ¹®ÀÇ : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.