Answered udf function not returnint proper value

  • 9 มีนาคม 2554 15:11
     
     

    I am trying to create a simple function to return a string value but the problem it returns only 1 char instead of the full work
    [code]
    -- Declare the return variable here
    DECLARE @mois nvarchar(10)
    -- Add the T-SQL statements to compute the return value here

     

    RETURN CASE @inMth
    WHEN 'Jan' THEN 'Janvier'
    WHEN 'Feb' THEN 'Fevrier'
    WHEN 'Mar' THEN 'Mars'
    WHEN 'Apr' THEN 'Avril'
    WHEN 'May' THEN 'Mai'
    WHEN 'Jun' THEN 'Juin'
    WHEN 'Jul' THEN 'Juillet'
    WHEN 'Aug' THEN 'Aout'
    WHEN 'Sep' THEN 'Septembre'
    WHEN 'Oct' THEN 'Octobre'
    WHEN 'Nov' THEN 'Novembre'
    WHEN 'Dec' THEN 'Decembre'
    END

    -- Return the result of the function

     

    RETURN @mois
    [/code]

    when I run the following I get J as the returm value 

    select

     

    @m= dbo.udf_TranslateMonthToFrench('Jan')
    print @m

    Thanks

ตอบทั้งหมด

  • 1 เมษายน 2554 19:10
     
     

    Hi Alabil,

    Please could you post the whole function declaration, including the function header and the line where you declare @inMth

    Thanks.


    Peter Carter-Greenan http://sqlserverdownanddirty.blogspot.com/
  • 5 พฤษภาคม 2554 15:20
     
     คำตอบ มีโค้ด

    make sure the returned type is right

    RETURNS NVARCHAR(10)