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.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Count & Group By but NOT null

Author  Topic 

mikeallenbrown
Yak Posting Veteran

72 Posts

Posted - 2014-03-12 : 20:32:08
I want to exclude NULLs and blanks from this query ...having a heck of a time with the syntax

SELECT PrimaryDiag,  Count(*)  AS EXP 
FROM Patient
GROUP BY PrimaryDiag
ORDER BY EXP DESC


-Mike

Mike Brown

stepson
Aged Yak Warrior

545 Posts

Posted - 2014-03-13 : 02:02:15
[code]
SELECT PrimaryDiag, Count(*) AS EXP
FROM Patient
WHERE PrimaryDiag is null or PrimaryDiag<>''
GROUP BY PrimaryDiag
ORDER BY EXP DESC
[/code]


sabinWeb MCP
Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2014-03-13 : 08:12:04
A small correction

quote:
Originally posted by stepson


SELECT PrimaryDiag, Count(*) AS EXP
FROM Patient
WHERE PrimaryDiag is NOT null or PrimaryDiag<>''
GROUP BY PrimaryDiag
ORDER BY EXP DESC



sabinWeb MCP




Cheers
MIK
Go to Top of Page

mikeallenbrown
Yak Posting Veteran

72 Posts

Posted - 2014-03-13 : 09:25:55
Thank you!!

-Mike

Mike Brown
Go to Top of Page
   

- Advertisement -