我想通过 BCode 每月转移数据,并在表格中按月调出数据。当 BCode 发生变化时,我们可以确定该公司通过 BCode 转移到另一个类别,这意味着该公司已转移到该类别。
我希望转入并转出BCode = 1
表格
| Id Refno TransactionDate BCode ReceiptDate Total
+------------------------------------------------------------------------------------------+
| 70488974 K0702694 2014-01-01 00:00:00.000 1 2014-04-01 00:00:00.000 -1429,72 |
| 72107868 K0731218 2014-01-01 00:00:00.000 1 2015-01-01 00:00:00.000 -4052,65 |
| 70173504 K0770815 2014-01-01 00:00:00.000 23 2014-01-01 00:00:00.000 -706,46 |
| 70578306 K0773716 2014-01-01 00:00:00.000 99 2014-01-01 00:00:00.000 -443,45 |
| 70245176 K0702694 2014-02-01 00:00:00.000 1 2014-02-01 00:00:00.000 -1298,23 |
| 72225353 K0731218 2014-02-01 00:00:00.000 1 2015-02-01 00:00:00.000 -987,44 |
| 70942793 K0773716 2014-02-01 00:00:00.000 1 2014-05-01 00:00:00.000 -443,45 |
| 70947050 K0770815 2014-02-01 00:00:00.000 1 2014-05-01 00:00:00.000 270,26 |
| 70370825 K0702694 2014-03-01 00:00:00.000 1 2014-03-01 00:00:00.000 -1323,78 |
| 70298756 K0770815 2014-03-01 00:00:00.000 23 2014-02-01 00:00:00.000 -697,49 |
| 70578306 K0773716 2014-03-01 00:00:00.000 99 2014-04-01 00:00:00.000 -443,45 |
| 71564379 K0731218 2014-03-01 00:00:00.000 13 2014-09-01 00:00:00.000 -2236,26 |
输出应该是这样的:
每月转移(2014年2月1日起)
| Refno From BCode Total |
+-------------------------------+
| K0770815 23 270,26 |
| K0773716 99 -443,45 |
+-------------------------------+
每月转出(2014年2月1日起)
| Refno To BCode Total |
+-------------------------------+
| K0770815 23 270,26 |
| K0773716 99 -443,45 |
| K0731218 13 -2236,26 |
+-------------------------------+
我当前的代码如下所示
public DataSet _getMTIO(DateTime startMonth, long bCode)
{
var query_in = (from _in in _entities.Transactions
join _bcode in _entities.BCodes on _in.BCode equals _seta.SetaCode
where (_in.TransactionDate >= startMonth
|| startMonth == DateTime.MinValue)
&& (_in.BCode == bCode || bCode < 0)
&& !_entities.Transactions.Where(y => y.TransactionDate < startMonth)
.Select(y => y.Refno).Contains(_in.Refno)
select new
{
RefNo = _in.Refno,
FromBCode= _in.BCode,
Total = _in.Total
});
var query_out = (from _out in _entities.LevyTransactions
join _bcode in _entities.BCodes on _in.BCode equals _seta.SetaCode
where (_in.TransactionDate >= startMonth
|| startMonth == DateTime.MinValue)
&& (_out.BCode == bCode || bCode < 0)
&& !_entities.Transactions.Where(y => y.TransactionDate > startMonth)
.Select(y => y.BCode).Contains(_out.BCode)
select new
{
RefNo = _out.Refno,
ToBCode= _out.BCode,
Total = _out.Total_out.Total
});
}