Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

How do I Join Calendar table with other tables with sparse dates

$
0
0

Hi,

I 'd need an insight on how to join Calendar table (contains all 2013-14 dates, granularity - day) with 3 other tables with sparse dates but with same granularity - day.

Other 3 tables has similar info:

Refund Table: Brand, Vendor, Qty, RefundDate

Sales Table: Brand, Vendor, Qty, SalesDate

Purchase Table: Brand, Vendor, Qty, PurchaseDate

I'm trying to map up all dates from 3 business tables to Calendartable but NEED HELP with TSQL logic - what kind of JOIN should I use if I joining tables on different conditions:

select * from Calendar2013_2014

left outer join [Refund Table]
on [Refund Table].RefundDate=Calendar.Date

left outer join  [Sales Table]
on Calendar.Date=[Sales Table].SalesDate
and [Refund Table].Brand=[Sales Table].Brand
and [Refund Table].Vendor=[Sales Table].Vendor

left outer join [Purchase Table]
on Calendar.Date=[Purchase Table].PurchaseDate
and [Purchase Table].Brand=[Sales Table].Brand
and [Purchase Table].Vendor=[Sales Table].Vendor



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>