Showing posts with label return no null rows in sql with aggregate functions. Show all posts
Showing posts with label return no null rows in sql with aggregate functions. Show all posts

Sunday, January 10, 2016

Return no result set with Min / Max

Hi,

Just in case if you wondering how not to return NULL rows when aggregate functions couldnt find value, this is how you can do it!


If Object_Id('tempdb..#myTable') Is Not Null 
Drop Table #myTable;
Go

Create Table #myTable(col1 Integer Null, col2 Integer Null)
Insert #myTable(col1) values (1)

;With t_max(tmax, tmin) As
       (Select Max(col2), Min(col2)
       From #myTable)
Select tmax, tmin
From t_max
Where tmax Is Not Null And tmin Is Not Null




HTH