Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
divan
Posting Yak Master
153 Posts |
Posted - 2013-04-10 : 07:58:56
|
I have a table that has a column named RELATIONSHIP_CD where the code can be H,G, T and also NULL.. I have written a script SELECT COUNT(C.RELATIONSHIP_CD) ,C.RELATIONSHIP, E.DESCRIPTIONFROM CLAIM CLEFT INNER JOIN EDIT_LONG_CODE E ON E.TBNAME = 'CLAIM' AND E.NAME = 'RELATIONSHIP' AND E.CODE = C.RELATIONSHIPGROUP BY C.RELATIONSHIP, E.DESCRIPTIONwhen I run the script I get the correct count for all the codes but for the Null I get 0 (zero) even though there are 34 records that have null so what am I missing or doing wrong.. |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-04-10 : 08:15:02
|
SELECT COUNT(*) ,C.RELATIONSHIP, E.DESCRIPTIONFROM CLAIM CLEFT INNER JOIN EDIT_LONG_CODE E ON E.TBNAME = 'CLAIM' AND E.NAME = 'RELATIONSHIP' AND E.CODE = C.RELATIONSHIPGROUP BY C.RELATIONSHIP, E.DESCRIPTIONCOUNT(*) --> will count NULLsCOUNT(ColumnName) --> will never consider NULLs |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-11 : 02:16:39
|
if attempt is to count instances of RELATIONSHIP_CD you may be better off putting it asSELECT COUNT(*) AS Cnt,C.RELATIONSHIP_CDFROM CLAIM CLEFT JOIN EDIT_LONG_CODE E ON E.TBNAME = 'CLAIM' AND E.NAME = 'RELATIONSHIP' AND E.CODE = C.RELATIONSHIPGROUP BY C.RELATIONSHIP, E.DESCRIPTION,C.RELATIONSHIP_CD so that you can see code values side by side with counts------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|