spiff2002
IS-IT--Management
- Jan 31, 2003
- 40
Let's say I have to small tables
customer
id name
1 cust1
2 cust2
3 cust3
4 cust4
Sales
inv# custid date sale
1 1 2004-12-03 $203.56
2 1 2004-12-04 $405.67
3 2 2004-12-04 $304.68
4 3 2004-12-05 $200.00
If I want to run a sales report for the month of December 2004
I run this Query
Select customer.id, customer.name sum(sales.sale) from Sales inner join customer on customer.id=sales.custid
where year(sales.date)='2004' an month(sales.date)='12'
group by
customer.id,
customer.name
and the end result should be this
id name sales
1 Cust1 609.23
2 Cust2 304.68
3 cust3 200.00
Now if I want to include cuatomer with no sales the I would have to change my iiner join to a right join like this
Select customer.id, customer.name sum(sales.sale) from customer right outer join Sales on customer.id=sales.custid
where year(sales.date)='2004' an month(sales.date)='12'
group by
customer.id,
customer.name
and the end result should be this
id name sales
1 cust1 609.23
2 cust2 304.68
3 cust3 200.00
4 cust4 NULL
This may be very simple to answer but how can I replace the Null result with a 0 or if the column was a varchar type column how can i replace it with an empty character '' ?????
I'm running MS SQL server 2000
Thank you in advance
customer
id name
1 cust1
2 cust2
3 cust3
4 cust4
Sales
inv# custid date sale
1 1 2004-12-03 $203.56
2 1 2004-12-04 $405.67
3 2 2004-12-04 $304.68
4 3 2004-12-05 $200.00
If I want to run a sales report for the month of December 2004
I run this Query
Select customer.id, customer.name sum(sales.sale) from Sales inner join customer on customer.id=sales.custid
where year(sales.date)='2004' an month(sales.date)='12'
group by
customer.id,
customer.name
and the end result should be this
id name sales
1 Cust1 609.23
2 Cust2 304.68
3 cust3 200.00
Now if I want to include cuatomer with no sales the I would have to change my iiner join to a right join like this
Select customer.id, customer.name sum(sales.sale) from customer right outer join Sales on customer.id=sales.custid
where year(sales.date)='2004' an month(sales.date)='12'
group by
customer.id,
customer.name
and the end result should be this
id name sales
1 cust1 609.23
2 cust2 304.68
3 cust3 200.00
4 cust4 NULL
This may be very simple to answer but how can I replace the Null result with a 0 or if the column was a varchar type column how can i replace it with an empty character '' ?????
I'm running MS SQL server 2000
Thank you in advance