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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Display record in tabular group by date-two table

Author  Topic 

micnie_2020
Posting Yak Master

232 Posts

Posted - 2010-04-08 : 23:43:34
Dear All,

I have 2 table

Table A
--------

NDate NBV NDP
1/3/2010 10 20
2/3/2010 5 64


Table B
--------

ADate ABV ADP
1/3/2010 51 6
4/3/2010 7 81


Output Needed
--------------

Date NBV NDP ABV ADP
1/3/2001 10 20 51 6
2/3/2010 5 64 0 0
4/3/2010 0 0 7 81


Please Advise


Thank you.


Regards,
Micheale

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-04-08 : 23:53:16
[code]
select [Date] = coalesce(a.[NDate], b.[ADate]),
NBV = coalesce(a.NBV, 0),
NDP = coalesce(a.NDP, 0),
ABV = coalesce(b.ABV, 0),
ADP = coalesce(b.ADP, 0)
from tablea a
full outer join tableb b on a.[NDate] = b.[ADate]
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -