Results 1 to 1 of 1
  1. #1
    Join Date
    Oct 2012
    Posts
    1

    Unanswered: Snag - code seems to incorrect SUM()

    Hey everyone,

    I'm using Sql Server Report Builder 2008 to make a report. The following query gives me the right record when I enter a value in @debnr but if I don't it sums up "Bedrag" and "Marge".

    Where did I go wrong?

    Thx in advance.


    Code:
    SELECT C.cmp_name, 
           C.cmp_code,
    	   C.cmp_fctry,
    	   C.textfield4  AS ABP_Nummer, 
    	   C.textfield5  AS AGB_Code, 
    	   C.yesnofield1 AS NL_Ziekenhuis, 
    	   C.yesnofield2 AS BE_Ziekenhuis,
    		X.bedrag,
    		R.Marge
    FROM   cicmpy C 
    JOIN (SELECT Sum(tot_bdr) AS Bedrag, 
                        fakdebnr,
                        faknr
                 FROM   frhkrg
           		WHERE fakdat BETWEEN @beginDatum AND @eindDatum 
                 GROUP  BY fakdebnr,faknr) X 
             ON X.fakdebnr = C.debnr
    INNER JOIN (SELECT SUM((prijs_n*esr_aantal)-(vvp*esr_aantal)) AS Marge,
    		    faknr
    	     FROM   frhsrg
    		GROUP BY faknr) R
    	 ON X.faknr = R.faknr
    JOIN (SELECT CASE WHEN textfield4 IS NULL THEN 0 ELSE '1' END AS APB, 
    CASE WHEN textfield5 IS NULL THEN 0 ELSE '1' END AS AGB, cmp_code from cicmpy) P ON P.cmp_code = C.cmp_code
    WHERE C.cmp_type = 'C' 
           AND C.cmp_code = COALESCE(@debnr,C.cmp_code)
           AND C.yesnofield1 = @NL 
           AND P.AGB = (@AGB) 
           AND C.yesnofield2 = @BE 
           AND P.APB = (@APB)
    Already solved, the problem was a extra sum option in the report itself. I forgot to reset the textbox expression, from when i coded from another angle.
    Last edited by slemmen; 10-29-12 at 05:26.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •