Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2015
    Posts
    2

    Unanswered: Help with Select in Query?

    Hey guys,

    brand new to SQL and have a question. In the select statement I wanted to select either PO_NOTTOEXCEED_VALUE if the PO_SUBTYPE is 'BO' or just select PCOM_VALUE_THISREV for all other PO_SUBTYPEs. You can see my SQL below:



    Code:
    SELECT PO_HEADERS.PO_SEQNO, 
    PO_HEADERS.PO_NUMBER, 
    PO_AWARD, 
    POCL_VTYV_VALUE, 
    (IF PO_SUBTYPE = 'BO'
    THEN PO_NOTTOEXCEED_VALUE, PCOM_VALUE_THISREV), 
    PCOM_NEGOTIATED_SAVING, 
    PCOM_REVNO 
    FROM PO_CLASSES, PO_HEADERS, PROJECT_COMMITMENTS 
    WHERE     POCL_PO_SEQNO = PO_HEADERS.PO_SEQNO 
    AND PCOM_DATASEQNO = PO_HEADERS.PO_SEQNO 
    AND POCL_VTYV_VALUE = 'OBE'
    AND PO_AWARD >= ADD_MONTHS (TRUNC (SYSDATE, 'MM'), -12)
    AND PO_AWARD < ADD_MONTHS (TRUNC (SYSDATE, 'MM'), 1)
    AND PCOM_REVNO = 0 
    AND PO_SUBTYPE <> 'REL'
    GROUP BY PO_HEADERS.PO_SEQNO, 
    PO_HEADERS.PO_NUMBER, 
    PO_RELEASE_NUMBER, 
    PO_AWARD, 
    POCL_VTYV_VALUE, 
    PCOM_VALUE_THISREV, 
    PCOM_NEGOTIATED_SAVING, 
    PCOM_REVNO;
    The select statement is where my concern lies. Any ideas? Thanks.

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    CASE (or DECODE) might do what you are looking for:
    Code:
    select
      ..., 
      case when po_subtype = 'BO' then po_nottoexceed_value
           else pcom_value_thisrev
      end,
      ...
    from ...

Posting Permissions

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