1:create view bbps_vwNegativeAdjustmentSplits as
   2:select
   3:        noOrigVals.adjustmentSequence,
   4:        
   5:        noOrigVals.giftLinkId,
   6:        
   7:        -1 * prevSplit.giftsplitid as giftSplitId,
   8:        null as giftid,
   9:        noOrigVals.originalGiftId,
  10:        noOrigVals.adjustmentid,
  11:
  12:        
  13:        -1 * prevSplit.amount as amount,
  14:        prevSplit.fundid,
  15:        prevSplit.campaignid,
  16:        prevSplit.appealid,
  17:        prevSplit.packageid,
  18:        prevSplit.sequence,
  19:        prevSplit.import_id 
  20:
  21:from
  22:        (
  23:        select distinct
  24:                adjustmentSequence,
  25:                giftLinkId,
  26:                originalGiftId,
  27:                adjustmentid
  28:        from 
  29:                bbps_vwPreAdjustmentSplits
  30:        where 1=1
  31:        and adjustmentSequence > 0
  32:        ) as noOrigVals
  33:        
  34:        inner join
  35:        bbps_vwPreAdjustmentSplits prevSplit
  36:                on prevSplit.originalGiftId = noOrigVals.originalGiftId
  37:                and prevSplit.adjustmentSequence = noOrigVals.adjustmentSequence -1
  38:
  39:--where noOrigVals.originalGiftId = 1143
  40: