对。所以我有以下 SQL Server 查询:
SELECT St.Financial_Account_ID, St.Business_ID, St.Financial_Account_Desc, St.Financial_Account_Type_ID, St.Financial_Account_Active,
St.Financial_Account_OpeningBalance, St.CRTotal, St.DRTotal, CASE st.Financial_Account_Type_ID WHEN 1 THEN (DRTotal - CRTotal)
WHEN 2 THEN (CRTotal - DRTotal) WHEN 3 THEN (CRTotal - DRTotal) WHEN 4 THEN (DRTotal - CRTotal) END AS Balance,
Financial_Account_Type.Financial_Account_Type_Desc
FROM (SELECT Financial_Account_ID, Business_ID, Financial_Account_Desc, Financial_Account_Type_ID, Financial_Account_Active,
Financial_Account_OpeningBalance,
(SELECT ISNULL(SUM(Financial_Transaction_Amount), 0) AS Expr1
FROM Financial_Transaction AS Financial_Transaction_1
WHERE (Financial_Transaction_CR_AccountID = FA.Financial_Account_ID) AND (Financial_Transaction_Date <= @ToDate)) AS CRTotal,
(SELECT ISNULL(SUM(Financial_Transaction_Amount), 0) AS Expr1
FROM Financial_Transaction AS Financial_Transaction_2
WHERE (Financial_Transaction_DR_AccountID = FA.Financial_Account_ID) AND (Financial_Transaction_Date <= @ToDate)) AS DRTotal
FROM Financial_Account AS FA) AS St INNER JOIN
Financial_Account_Type ON St.Financial_Account_Type_ID = Financial_Account_Type.Financial_Account_Type_ID
WHERE (St.Financial_Account_Type_ID = 1 OR
St.Financial_Account_Type_ID = 2) AND (St.Business_ID = @BusinessID) AND (CASE st.Financial_Account_Type_ID WHEN 1 THEN (DRTotal - CRTotal)
WHEN 2 THEN (CRTotal - DRTotal) WHEN 3 THEN (CRTotal - DRTotal) WHEN 4 THEN (DRTotal - CRTotal) END <> 0)
这得到了我的资产负债表,并在 Telerik 报告中使用,因此变量等。
我现在需要创建一个“比较资产负债表”,这并不太复杂,但要做到这一点,我需要生成两次不同日期的上述报告,并制作一个百分比更改列。
我可以看到如何做这一切,但是当我完成时它会变得非常混乱,调试某些东西将是一件苦差事,更重要的是,一旦一切都说完了,这将是一个非常简单的例子。它只会从这里变得更加复杂。
我正在寻找的是:
一个查询构建器类型的东西,它将简化我正在生成的子表的调试,或者是否有更程序化的方式来编写这些东西......例如
查询去查询去
这种东西有用吗?以及如何将所有内容链接在一起?还没有找到任何文章,但是一切似乎都只介绍了基本的选择语句。
很高兴自己阅读,只需要朝着正确的方向前进。
谢谢你的帮助