SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 query select
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

afri
Starting Member

Indonesia
8 Posts

Posted - 03/12/2014 :  14:23:24  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3761 Posts

Posted - 03/12/2014 :  16:41:01  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000