SQLTeam.com | Weblogs | Forums

User Defined Function Return Chinese Value


#1

Hi,

I have the following user defined functions:

USE [AES_LWM]
GO
/****** Object:  UserDefinedFunction [TRANSACTIONS].[cfn_GetDateByLanguage]    Script Date: 12/07/2015 15:21:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


ALTER FUNCTION [TRANSACTIONS].[cfn_GetDateByLanguage]
(
    @Date date,
    @Language varchar(50)
)
RETURNS nvarchar(50)
AS
BEGIN
    DECLARE @Return_Value nvarchar(50)
    
    IF MONTH(@Date) = 1
     BEGIN
        SET @Return_Value = CASE WHEN @Language = 'CN' THEN '一月' 
                                 WHEN @Language = 'MA' THEN 'Jan'
                                 ELSE 'Jan' END
     END
     
    IF MONTH(@Date) = 2
     BEGIN
        SET @Return_Value = CASE WHEN @Language = 'CN' THEN '二月' 
                                 WHEN @Language = 'MA' THEN 'Feb'
                                 ELSE 'Feb' END      
     END

    IF MONTH(@Date) = 3
     BEGIN
        SET @Return_Value = CASE WHEN @Language = 'CN' THEN '三月' 
                                 WHEN @Language = 'MA' THEN 'Mac'
                                 ELSE 'Mar' END      
     END
     
    IF MONTH(@Date) = 4
     BEGIN
        SET @Return_Value = CASE WHEN @Language = 'CN' THEN '四月' 
                                 WHEN @Language = 'MA' THEN 'Apr'
                                 ELSE 'Apr' END
     END
     
    IF MONTH(@Date) = 5
     BEGIN
        SET @Return_Value = CASE WHEN @Language = 'CN' THEN '五月' 
                                 WHEN @Language = 'MA' THEN 'Mei'
                                 ELSE 'May' END    
     END
     
    IF MONTH(@Date) = 6
     BEGIN
        SET @Return_Value = CASE WHEN @Language = 'CN' THEN '六月' 
                                 WHEN @Language = 'MA' THEN 'Jun'
                                 ELSE 'Jun' END
     END
     
    IF MONTH(@Date) = 7
     BEGIN
        SET @Return_Value = CASE WHEN @Language = 'CN' THEN '七月' 
                                 WHEN @Language = 'MA' THEN 'Jul'
                                 ELSE 'Jul' END    
     END
     
    IF MONTH(@Date) = 8
     BEGIN
        SET @Return_Value = CASE WHEN @Language = 'CN' THEN '八月' 
                                 WHEN @Language = 'MA' THEN 'Ogos'
                                 ELSE 'Aug' END
     END
     
    IF MONTH(@Date) = 9
     BEGIN
        SET @Return_Value = CASE WHEN @Language = 'CN' THEN '九月' 
                                 WHEN @Language = 'MA' THEN 'Sep'
                                 ELSE 'Sep' END    
     END
    
    IF MONTH(@Date) = 10
     BEGIN
        SET @Return_Value = CASE WHEN @Language = 'CN' THEN '十月' 
                                 WHEN @Language = 'MA' THEN 'Okt'
                                 ELSE 'Oct' END       
     END
     
    IF MONTH(@Date) = 11
     BEGIN
        SET @Return_Value = CASE WHEN @Language = 'CN' THEN '十一月' 
                                 WHEN @Language = 'MA' THEN 'Nov'
                                 ELSE 'Nov' END          
     END
    
    IF MONTH(@Date) = 12
     BEGIN
        SET @Return_Value = CASE WHEN @Language = 'CN' THEN '十二月' 
                                 WHEN @Language = 'MA' THEN 'Dis'
                                 ELSE 'Dec' END        
     END
     
    RETURN @Return_Value
END

I tried to SELECT TRANSACTIONS.cfn_GetDateByLanguage(GETDATE(), 'CN') but it return ??? and not the chinese value.

How can I do?


#2

TRY SELECT dbo.TRANSACTIONS.cfn_GetDateByLanguage(GETDATE(), 'CN')