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 2012 Forums
 Transact-SQL (2012)
 query select

Author  Topic 

afri
Starting Member

8 Posts

Posted - 2014-03-12 : 14:23:24
w have 2 table :item and transaction
item transaction
id name period id area amount
1 clothes 2011-10 1 north 1200
2 bike 2011-11 1 west 1300
3 car 2011-11 2 east 300

result
period id amount
2011-10 1 1200
2011-10 2 0
2011-10 3 0
2011-11 1 1300
2011-11 2 300
2011-11 3 0

i have tried to create query for get a data like a table result above
but still not macth
my query
select b.period,a.id,b.amount from transaction b left join item a on a.id =b.id order by date

please help for this.thanks

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-03-12 : 16:41:01
Create a calendar table that has all the periods that you want to show in the output data. Then left join your two tables to that new table.

What is the data type of the period column in your existing tables?
Go to Top of Page
   

- Advertisement -