2016-10-24 38 views
1

這是我的左連接查詢,我自動開發信用借記卡和餘額。無法在十進制中調用方法SQL Server錯誤

也許我缺乏專欄。我使用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)[email protected]*/ 
    ORDER BY 
     gLedeger.gl_date 
END 
+0

確保您的代碼被格式化爲用於提高易讀性的代碼 –

+0

您在查詢中具有聚合函數但未使用GROUP by子句 –

+0

我只是編碼的初學者可以告訴我如何在上述查詢中使用組? ?? –

回答

0

我得到這個解決方案如下: - 。

ALTER過程[DBO] [fulltest] ( @gl_acid INT, @userid INT ) 作爲 開始

SELECT ROW_NUMBER()OVER(由gLedeger.PK_id順序)以SnO,情況下,當master.ma_accname是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, 情況下,當gLedeger.GL_DRCR < 0,則ABS(gLedeger.gl_drcr)否則0.00端信貸, SUM(gLedeger.gl_drcr)OVER(ORDER BY gledeger.pk_ID ROWS UNBOUNDED PRECEDING)AS餘額
FROM gLedeger LEFT JOIN主ON gLedeger .GL_ACID = master.PK_ID留在[email protected] WHERE gLedeger.GL_ACID = @gl_acid /和LEFT(gLedeger.gl_voucher,2)= @憑單/

加入登記ř
ORDER BY gLedeger.gl_date 

end