I have 2 tables I’m trying to join in SQL Server. Table one is a list of salesId‘s and table two is a list of average sales per month by salesId.
Table1 :
SalesId
0001
0004
0345
1009
2290
....
Table2:
SalesId AvgMnthSales
0001 22253.34
0002 8970.28
0003 15377.45
0004 349.03
0005 3498.44
.... ...
So I do a join like this:
Select t1.SalesId, t2.AvgMnthSales
from table1 t1
left join
table2 t2
on t1.SalesId = t2.SalesId
and get something like this:
SalesId AvgMnthSales
0001 22253.34
0004 349.03
0345 NULL
1009 NULL
2290 8846.56
.... ....
What I’d prefer is to have any NULL converted to 0. I’ve seen some examples where this was done in a two step process of sending the results to a temp table and then converting NULL‘s to 0‘s, but was curious if there’s a single step way to do this.
The reason is largely due to ignorance. I’m not sure how temp tables are handled (in RAM or on disk) and how much space they take up as this is a large data set and it would likely take up several GB‘s of RAM or disk space.
Any suggestions would be appreciated.
1 Answer