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.
| Author |
Topic |
|
venki.dmm
Starting Member
10 Posts |
Posted - 2009-04-06 : 05:49:34
|
| Hi All,I am having the 2 tables 1)sales Table 2)purchase TableSales TableStore_Name Salesaa 10bb 20cc 30Purchase Table Store_Name Purchaseaa 10dd 40OutPut Required Store_name Sales Purcahseaa 10 10bb 20 0cc 30 0 dd 0 40Can you please help meRegards,Venki |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-06 : 06:06:23
|
| --Method 1select Store_Name,max(sales) as sales, max(purchase) as purchase from(select Store_Name,sales,0 as purchase from salesunion allselect Store_Name,0, purchase from purchase) as tgroup by Store_Nameorder by Store_Name--Method 2select coalesce(s.Store_Name,p.Store_Name),coalesce(s.Sales,0) as sales,coalesce(p.Purchase,0) as purchase from sales as s full join Purchase as pon s.Store_Name=p.Store_Name order by 1MadhivananFailing to plan is Planning to fail |
 |
|
|
venki.dmm
Starting Member
10 Posts |
Posted - 2009-04-06 : 07:33:03
|
| Hi MadhivananThanks for your replyiam using this Query.--Method 2It is working fine but i am having the date column in both table1)sales 2)purchasewhen i am trying with date it is showing duplication columnsselect coalesce(s.Store_Name,p.Store_Name),coalesce(s.Sales,0) as sales,coalesce(p.Purchase,0) as purchase from sales as s full join Purchase as pon s.Store_Name=p.Store_Name order by 1can you please help me |
 |
|
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2009-04-06 : 07:49:32
|
| hi try this too,select storename,isnull(sales,0) as sales,isnull(purchase,0) as purchase from sales s left join purchase pon s.storename = p.storepurchaseunion select storepurchase,isnull(sales,0) as sales,isnull(purchase,0) as purchase from sales s right join purchase pon s.storename = p.storepurchase |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-06 : 08:49:16
|
quote: Originally posted by venki.dmm Hi MadhivananThanks for your replyiam using this Query.--Method 2It is working fine but i am having the date column in both table1)sales 2)purchasewhen i am trying with date it is showing duplication columnsselect coalesce(s.Store_Name,p.Store_Name),coalesce(s.Sales,0) as sales,coalesce(p.Purchase,0) as purchase from sales as s full join Purchase as pon s.Store_Name=p.Store_Name order by 1can you please help me
Post the query that has problemMadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-06 : 08:50:57
|
quote: Originally posted by soorajtnpki hi try this too,select storename,isnull(sales,0) as sales,isnull(purchase,0) as purchase from sales s left join purchase pon s.storename = p.storepurchaseunion select storepurchase,isnull(sales,0) as sales,isnull(purchase,0) as purchase from sales s right join purchase pon s.storename = p.storepurchase
Full join actually does this MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|