473,407 Members | 2,315 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Problem with NULL values

1
I have two tables. grtbk and gbkmut. both link by reknr(Account Number)

grtbk holds all of my General Ledger Accounts.
gbkmut holds trx's for each account.

When I have a month with no transactions I still want a record returned that shows 0.

I have the following Code:
SELECT TOP (100) PERCENT dbo.gbkmut.reknr, ISNULL(SUM(dbo.gbkmut.bdr_hfl), 0) AS Amount, dbo.grtbk.bal_vw, YEAR(dbo.gbkmut.datum) AS Year,
MONTH(dbo.gbkmut.datum) AS Month
FROM dbo.gbkmut LEFT OUTER JOIN
dbo.grtbk ON dbo.gbkmut.reknr = dbo.grtbk.reknr
GROUP BY dbo.gbkmut.reknr, dbo.grtbk.bal_vw, YEAR(dbo.gbkmut.datum), MONTH(dbo.gbkmut.datum), dbo.gbkmut.transtype
HAVING (dbo.grtbk.bal_vw = 'W') AND (dbo.gbkmut.transtype <> 'V')
ORDER BY 'Year', Month

--------------------------------------------------------------
Which returns the following. The ISNULL() does not seem to be working. I still want to see month 4 and 5 with a 0 amount.
reknr Amount bal_vw YEAR MONTH
41401 -47.79 W 2009 1
41401 -47.31 W 2009 2
41401 -23.3 W 2009 3
41401 22.87 W 2009 6
Sep 28 '09 #1
1 1699
Delerna
1,134 Expert 1GB
grtbk has all records and gbkmut may or may not have records
You need to join the "might have records" to the "always has records"


You have left joined gbkmut (might Have Records) to grtbk (always has records).
It should be the other way around.



Expand|Select|Wrap|Line Numbers
  1. SELECT blah blah
  2. FROM grtbk
  3. LEFT JOIN gbkmut on grtbk.reknr = gbkmut.reknr 
  4. blah blah
  5.  
Notice above the "always has records" table is on the left so we use a LEFT join


Alternatively, as your query is now, you could use a RIGHT join instead,
because the "always has records" table is on the right
Sep 29 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: sinasalek | last post by:
i have a problem with MySQL 4.1.x and UTF8. in version 4.0, i'm using html forms with utf8 charset for inserting unicode strings. but in version 4.1.x it is not working! if i change the charset of...
0
by: Dean A. Hoover | last post by:
I am doing a contract job for a client with some existing messy data. I am trying to find a solution to a problem of many-to-many mappings between two tables in a database. See below for my...
2
by: Gunnar Vøyenli | last post by:
Hi Some days ago I posted a problem with a query. Thaks to Dave and John, I got a little closer to a solution. Their suggestion was a solution to my problem as I stated it, but the real problem...
6
by: scott | last post by:
i've come across a real head-hurter. I'm looping through a recordset and response.writing it's rows out with no problem except 1 field. The field type is varchar and contains words like meeting,...
3
by: Myron | last post by:
I'm trying to create a query that will tell me which requests took longer than 10 days to move one from particular state to another state. The query I've created returns the correct requests, but...
4
by: Dani | last post by:
Hi everyone Description of the problem: Using a PreparedStatement to write down an integer (int) plus a timestamp for testing purposes. When read out again the integer looks very different. We...
30
by: dbuchanan | last post by:
ComboBox databindng Problem == How the ComboBox is setup and used: My comboBox is populated by a lookup table. The ValueMember is the lookup table's Id and the DisplayMember is the text from a...
2
by: mob1012 via DBMonster.com | last post by:
Hi All, I wrote last week about a trigger problem I was having. I want a trigger to produce a unique id to be used as a primary key for my table. I used the advice I received, but the trigger is...
10
by: Rudolf Bargholz | last post by:
Perhaps some kind soul could help me out with an SQL I have been trying all day to get to work, where one colum is just not summing up the way I want it to. I have the following data GRP_SEQ ...
0
by: ZoeNet | last post by:
Hi all, The table structures are below. The table category_cat is built on the adjacency model (where the parent and child entries are both stored in the same table). For my problem, I've...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.