Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2009
    Posts
    6

    Unanswered: how can i output 2 rows using a single query

    i need to breakdown the amount into 2 rows, splitting the 80% and 20% to 2 accounts.

    select jd.account, jd.usage, jd.prod_code,
    (case when jd.prod_code = 'VD00'
    then jd.amount * .8 --> the other account (default to 21160 has 20% of the jd.amount)
    else
    jd.amount
    end) amount
    from jnl_detail jd


    input:
    account,usage,prod_code,amount
    31104,1,VD00,10

    my output should be:
    31104,1,VD00,8
    21160,1,'',2

    thanks for your help.

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Code:
    select 
      jd.account, 
      jd.usage, 
      jd.prod_code,
      (case when jd.prod_code = 'VD00' 
        then jd.amount * .8 
        else jd.amount
      end) amount
    from jnl_detail jd
    
    union all
    
    select
      21160,
      jd.usage, 
      '',
      jd.amount * .2
    from jnl_detail jd
    where jd.prod_code = 'VD00'
    ---
    "It does not work" is not a valid problem statement.

Posting Permissions

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