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
 General SQL Server Forums
 New to SQL Server Programming
 Combine two query with different number of row set

Author  Topic 

Petronas
Posting Yak Master

134 Posts

Posted - 2009-04-02 : 11:28:36
Hi All,

I have the below queries. What I want to do is combine them both..
But the first query for actives has a result set of 7 rows.
Data is from Jul 2008 to Jan 2009
whereas the second query for the cancels has only 6 rows.
Data is from Aug 2008 to Jan 2009.
How do I go about putting a NULL or 0 for Jul 2008 in the Cancels.

--Actives
select count(customer_id)Active_counts,
convert(Datetime, convert(varchar(2), month(order_received_date)) +'/1/' + convert(varchar(4), year (order_received_date)) )Enroll_month
from orders with (nolock)
where product_id in ('MB01')
and order_received_date < '02/1/2009'
and (cancel_date is null or Cancel_Date >= '02/1/2009' )
group by convert(Datetime, convert(varchar(2), month(order_received_date)) +'/1/' + convert(varchar(4), year (order_received_date)) )
order by 2

--Cancels
select count(customer_id)Cancel_counts,
convert(Datetime, convert(varchar(2), month(cancel_date)) +'/1/' + convert(varchar(4), year (cancel_date)) )Cancel_month
from orders with (nolock)
where product_id in ('MB01')
and Cancel_Date < '02/1/2009'
group by convert(Datetime, convert(varchar(2), month(cancel_date)) +'/1/' + convert(varchar(4), year (cancel_date)) )
order by 2


Thanks,
Petronas
   

- Advertisement -