lundi 11 janvier 2021

Function input number and need to return te name of the month [duplicate]

I want to insert a number in function and get in return the name of the month according to the number I have tried CASE, IF, SET and so on. Still not working (syntax error near IF line 6)

    ALTER FUNCTION fn_Return_monthname (@monthPart INT)
    returns VarChar(50) 
    begin
      declare valjund VarChar(50);
      SET valjund = 'Unknow month'
      IF @monthPart = 1;
        SELECT valjund = 'January'
      ELSE IF @monthPart = 2
        SELECT valjund = 'February'
      ELSE IF @monthPart = 3
        SELECT valjund = 'March'
      ELSE IF @monthPart = 4
        SELECT valjund = 'April'
      ELSE IF @monthPart = 5
       SELECT valjund = 'May'
      ELSE IF @monthPart = 6
       SELECT valjund = 'June'
      ELSE IF @monthPart = 7
       SELECT valjund = 'July'
      ELSE IF @monthPart = 8
       SELECT valjund = 'August'
      ELSE IF @monthPart = 9
       SELECT valjund = 'September'
      ELSE IF @monthPart = 10
       SELECT valjund = 'October'
      ELSE IF @monthPart = 11
       SELECT valjund =  'November'
      ELSE IF @monthPart = 12
       SELECT valjund =  'December'
      return valjund;
    end;

Aucun commentaire:

Enregistrer un commentaire