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

    Unanswered: DB2 conversion problem

    //Hi i am beginner in DB2 and trying to convert MS sql code DB2 funtion code, but i am getting error plz resolve such type of error.

    Create FUNCTION GetProposalStatus(PSID Integer)
    Returns varchar(50)
    Language SQL
    Contains SQL
    Begin
    DECLARE Status VARCHAR(50);

    Set Status=
    (
    case PSID;
    when 1 then 'Pending';
    when 3 then 'Approved';
    when 2 then 'Rejected';
    End case;
    )
    Return Status;
    end

  2. #2
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    What error message code(s) and error texts did you got?


    Anyhow, the function might be simplified like,

    Example 1:
    Code:
    CREATE FUNCTION Get_Proposal_Status(psid INTEGER) 
    RETURNS VARCHAR(50) 
    LANGUAGE SQL
    CONTAINS SQL 
    DETERMINISTIC
    NO EXTERNAL ACTION
    RETURN
    CASE psid
    WHEN 1 THEN 'Pending'
    WHEN 3 THEN 'Approved'
    WHEN 2 THEN 'Rejected'
    END
    ;
    Example 2:
    Code:
    CREATE OR REPLACE FUNCTION Get_Proposal_Status
    (psid INTEGER) 
    RETURNS VARCHAR(50) 
    LANGUAGE SQL
    CONTAINS SQL 
    DETERMINISTIC
    NO EXTERNAL ACTION
    RETURN
    CASE
    WHEN psid IN (1, 2, 3) THEN
         SUBSTR('Pending RejectedApproved' , psid * 8 - 7 , 8)
    END
    ;

Posting Permissions

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