Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2013
    Posts
    11

    Unanswered: DB2 conversion problem

    //Hi, i am beginner in DB2, i want to make cenversion MS SQL to DB2 conversion bu i am getting error on Date formate conversion, could you please help as soon as possible.//

    create FUNCTION dbo.GetMonthYear(Date DateTime)
    RETURNS Varchar(20)
    LANGUAGE SQL
    CONTAINS SQL
    BEGIN
    DECLARE lsDate Varchar(20);
    IF Year(Date)>1900
    Set lsDate = (Case month(Date)
    When 1 then 'Jan ,' + CONVERT(char(4),Year(Date))
    When 2 then 'Feb ,' + CONVERT(char(4),Year(Date))
    When 3 then 'Mar ,' + CONVERT(char(4),Year(Date))
    When 4 then 'Apr ,' + CONVERT(char(4),Year(Date))
    When 5 then 'May ,' + CONVERT(char(4),Year(Date))
    When 6 then 'Jun ,' + CONVERT(char(4),Year(Date))
    When 7 then 'Jul ,' + CONVERT(char(4),Year(Date))
    When 8 then 'Aug ,' + CONVERT(char(4),Year(Date))
    When 9 then 'Sep ,' + CONVERT(char(4),Year(Date))
    When 10 then 'Oct ,' + CONVERT(char(4),Year(Date))
    When 11 then 'Nov ,' + CONVERT(char(4),Year(Date))
    When 12 then 'Dec ,' + CONVERT(char(4),Year(Date))
    END)
    else
    set lsDate = '';
    Return lsDate;
    END

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    For a DATETIME named d, I'd use:
    Code:
    SELECT MonthName(d) || ' ' || Cast(Year(d) AS CHAR(4))
    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •