sql - How to create view that combine multiple row from 2 tables? -
i want create view combine data 2 tables, sample data in each table below.
select command tablea
select [id], [date], [sum] tablea   result
id    |    date     |    sum 1     |    1/1/2010 |     2 1     |    1/2/2010 |     4 3     |    1/3/2010 |     6   select command tableb
select [id], [date], [sum] tableb   result
id    |    date     |    sum 1     |    1/1/2010 |     5 1     |    2/1/2010 |     3 1     |   31/1/2010 |     2 2     |    1/2/2010 |     20   i want output below
id    |    date     |    suma     |     sumb 1     |    1/1/2010 |     2       |      10 1     |    1/2/2010 |     4       |       0 2     |    1/2/2010 |     0       |      20 3     |    1/3/2010 |     6       |       0   how can on sql server 2005?
date information vary, modify in table.
try this...
select   isnull(tablea.id, tableb.id) id,   isnull(tablea.date, tableb.date),   isnull(tablea.sum,0) suma,   isnull(tableb.sum, 0) sumb   tablea full outer join tableb   on tablea.id = tableb.id , tablea.date = tableb.date order   id   a full outer join need because want include results both tables regardless of whether there match or not.
Comments
Post a Comment