how to retrieve data based on logic?

Given the table Transactions : (TrnNumber, TrnDate, Debit, Credit) and dates  startdate and endDate values, can i retrieve the following data :
  1- openingbalance : when Trndate < startdate return (Debit - Credit) else 0
  2- Debit                  : when TrnDate >= startdate and Trndate <= enddate then return Debit Else 0
  3- Credit                 : when TrnDate >= startdate and Trndate <= enddate then return Credit Else 0 
or should i retrieve All the data and iterate through it to do my logic .

Yes, you can do that using Condition projection: 


http://www.tmssoftware.biz/business/aurelius/doc/web/condition.html