Question

By using SQL Server 2000, I want to create a output data template as shown below using data's in table1 and table2

Output Data_Template

Unit1   | Sale_value_1  | Sale_value_2|
-------------------------------------------    
chart1  | 25             |12|
chart2  | 30             |0|
chart3  | 56             |0|
chart4  | 41             |98|

Table1

Date        |Unit1  |Sale_value_1|
------------------------------------    
2/11/2014   |chart1 |25|
2/11/2014   |chart2 |30|
2/11/2014   |chart3 |56|
2/11/2014   |chart4 |41|

Table2

Date        |Unit1  |Sale_value_2|
-----------------------------------    
2/11/2014   |chart1 |12|
2/11/2014   |chart2 |0|
2/11/2014   |chart3 |0|
2/11/2014   |chart4 |98|
Was it helpful?

Solution

This SQL Fiddle demonstrates the below query:

SELECT t1.Unit1, t1.Sale_value_1, t2.Sale_value_2 
FROM Table1 as t1
INNER JOIN Table2 as t2 ON t1.Unit1 = t2.Unit1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top