タイトルに基づいてtotal_amountを合計する必要があります。実際に私はこれらの2つのテーブルの間に関係はありませんが、貯蓄を取り出すために、私はそれらを合計し、両方の合計の合計を差し引く必要があります。私はtotal_Amountを合計する必要があります。title = incomeとtitle =経費
ALTER PROCEDURE [dbo].[SpSavingDetail]
@year varchar(10),
@month varchar(10)
AS
BEGIN
SET NOCOUNT ON;
declare @Saving int
select e.Date_time as Date_time ,c.category as Particular,e.Description as Description ,e.Amount as Amount,
e.Frequency as Frequency,e.Total_Amount as Total_Amount,'Expense' as Title from tbl_expense as e
left join tbl_category as c on c.Cat_id=e.Cat_id where datepart(MM,e.Date_time)[email protected] and datepart(YYYY,e.Date_time)[email protected]
union
select i.Date_time as Date_time ,s.source as Particular,i.Description as Description ,i.Amount as Amount,
i.Frequency as Frequency,i.Total_Amount as Total_Amount,'Income' as Title from tbl_income as i
left join tbl_source as s on s.Source_id=i.Source_id
where datepart(MM,i.Date_time)[email protected] and datepart(YYYY,i.Date_time)[email protected]
[1]: http://i.stack.imgur.com/8Z5po.jpg
このC#コードはどうですか? –
私は報告書で使用しているストアドプロシージャ – abcd