Skip to content
Advertisement

How to get NULL or Zero values in SQL Server results set

Trying to get the output of all mentioned accounts(total of 9) even though there are no existing records for the GB.periode = 11

Tried using ISNULL(SUM(GB.bdr_val), 0) but still I’m only getting output for GB.reknr = 5210 OR GB.reknr = 5211 OR GB.reknr = 5250 OR GB.reknr = 5340.

I have a sample DB layout below,

I still need the query output to show all the Total_Material_M, Desc2 and Account columns to show up even the values are 0 for specific bkjrcode and periode value combinations and SUMS, not sure what I’m doing wrong here.

Advertisement

Answer

If I understand correctly, you are looking for OUTER JOIN, INNER JOIN will return rows that match between all conditions on two tables.

For this below query RIGHT JOIN will return rows based on [dbo].[grtbk] even conditions didn’t match, But rows will be NULL when the row didn’t match by the conditions GB.bdr_val, so we need to use ISNULL in the aggregate function.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement