mccoya
mccoya

Reputation: 11

Omit null rows in results

Please help me figure this out...

I have a temporary table that has NULL values. I want to only extract one record, representing rows that have data. What I currently have in the table is

TableSample1

When I run the following statement,

SELECT * FROM #TempTable WHERE SICK IS NOT NULL AND VAC IS NOT NULL;

I want my results to be ResultsSample

Upvotes: 0

Views: 52

Answers (2)

Pawan Kumar
Pawan Kumar

Reputation: 2021

You can use MAX function..for this.

SELECT ID, MAX(SICK) SICK , MAX(VAC) VAC
FROM #TempTable
GROUP BY ID

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1271171

Use aggregation:

select id, sum(sick) as sick, sum(vac) as vac
from #TempTable
group by id;

Upvotes: 1

Related Questions