SQL语法中的LAG和LEAD替代

时间:2018-07-22 11:18:11

标签: sql sql-server database select zoho

My Table

你好,

我正在编写一个SQL查询以导出期末余额,其值将用于计算下一行的期初余额,依此类推。我的Table结构粘贴在上面的图像中,代码如下:

SELECT
         t1."Document Date" as txn_dt,
         t1."GL Account Code" as gl_code,
         t1."GL Account Description" as cst_name,
         t1."Debit Amount" as debit,
         t1."Credit Amount" as credit,
         t2."Opening Balance" as op_bal,
         t1."Debit Amount" + t1."Credit Amount" + t2."Opening Balance" as closing_bal
FROM  "Trial Balance 1617" t1,
     "GL Master Account" t2 
WHERE    t1."GL Account Code"  = t2."GL Account Code"
 AND    t1."GL Account Code"  = 'A3010101B058'

请注意,ZOHO报告不支持LAG和LEAD 有人可以引导我吗?

1 个答案:

答案 0 :(得分:1)

假设“试验余额1617”是汇总表,在总帐科目代码和凭证日期上具有唯一索引,则您可以手动计算导致特定条目的借方和贷方之和,如下所示:

InvariantCulture

返回:

dot

如果可以使用CTE,则可以通过在单独的查询中计算期初余额来对其进行大量清理:

decimal converted = Convert.ToDecimal(value, CultureInfo.InvariantCulture);