无法在十进制SQL Server错误中调用方法

时间:2016-10-24 10:09:53

标签: sql sql-server-2012

这是我的左连接查询,我自动开发信用借记和余额。

也许我缺乏专栏。我使用gl_drcr作为主列,并通过查询将其拆分为信用卡和借记卡,但我无法获得余额值。我也有金额列,我可以存储金额值。

你能帮我解决一下这个查询中我的错误吗?

我的存储过程如下所示:

ALTER procedure [dbo].[sp_getDataML]
    (@gl_acid int, @userid int)
AS
BEGIN
    SELECT 
        ROW_NUMBER() OVER (ORDER BY gLedeger.PK_id) AS sno,
        CASE 
           WHEN master.ma_accname IS NULL THEN '' 
           ELSE ma_accname 
        END AS AccName, 
        gLedeger.gl_date AS date, gLedeger.gl_narration AS Narration, 
        gLedeger.gl_drcr as DRCR,
        CASE
           WHEN gLedeger.gl_drcr > 0 THEN ABS(gLedeger.gl_drcr) 
           ELSE 0.00 
        END AS debit,
        CASE 
           WHEN gLedeger.gl_drcr < 0 THEN ABS(gLedeger.gl_drcr) 
           ELSE 0.00 
        END AS credit,
        SUM(COALESCE(gLedeger.gl_drcr.credit, 0) - COALESCE(gLedeger.gl_drcr.debit, 0)) AS Balance  
    FROM 
        gLedeger   
    LEFT JOIN 
        master ON gLedeger.GL_ACID = master.PK_ID 
    LEFT JOIN
        registration r ON master.userId = @userid
    WHERE 
        gLedeger.GL_ACID = @gl_acid
        /*and LEFT(gLedeger.gl_voucher,2)=@voucher*/
    ORDER BY 
        gLedeger.gl_date
END

2 个答案:

答案 0 :(得分:0)

我得到的解决方案如下: -

ALTER程序[dbo]。[fulltest] (   @gl_acid int,   @userid int   )   如   开始

SELECT ROW_NUMBER()OVER(按gLedeger.PK_id排序)为sno,当master.ma_accname为null时为&#39;&#39;否则ma_accname以AccName结尾,gLedeger.gl_date结束日期,gLedeger.gl_narration结束为Narration,gLedeger.gl_drcr结束为DRCR,     gLedeger.gl_drcr&gt;的情况0然后abs(gLedeger.gl_drcr)其他0.00结束为借记,     当gLedeger.GL_DRCR&lt; 0然后abs(gLedeger.gl_drcr)其他0.00以信用结束, SUM(gLedeger.gl_drcr)OVER(订购Gledeger.pk_ID ROWS UNBOUNDED PRECEDING)作为余额
    FROM gLedeger LEFT JOIN master ON     gLedeger.GL_ACID = master.PK_ID在master.userId=@userid上留下加入注册r     WHERE gLedeger.GL_ACID = @gl_acid     / 和LEFT(gLedeger.gl_voucher,2)= @ voucher /

ORDER BY gLedeger.gl_date

end

答案 1 :(得分:0)

SUM(COALESCE(gLedeger.gl_drcr.credit, 0) - COALESCE(gLedeger.gl_drcr.debit, 0)) AS Balance

在 sql 中不能在字段名后使用点。因为 Selecting fields 的格式是

<块引用>

SERVER.DATABASE.SCHEMA.FIELDNAME