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.
| Author |
Topic |
|
Pilgrim007
Starting Member
2 Posts |
Posted - 2009-08-18 : 07:55:42
|
| HiOn a particular period, some ITEM_NO's ,will not exist on one table (i.e. RTL_LOC_ITEM_DY).However I would like to see the ITEM_NO's, which do not exist, and return the values (even if it is NULL or 0) for the measures (e.g. SOH_UNITS). I will use DIM_ITEM as the main table to get the ITEM_NO's.I have tried several JOINT statements to DIM_ITEM (e.g. INNER, OUTER, LEFT OUTER, LEFT INNER), but still no luck. selectb.item_no,a.fin_year,a.fin_week,b.department,a.soh_unitsfromrtl_loc_item_dy ainner join dim_item bon b.item_no = a.item_no,dim_control c,dim_location lwhereb.item_no = a.item_no ANDa.fin_year = c.last_wk_year ANDa.fin_week = c.last_wk_week ANDl.location= a.location ANDb.department = 11 ANDa.fin_day = 7 ANDa.com_flag = 'Y' ANDb.rms_item_ind = 'Y' ANDl.chain_no=10 ANDl.loc_type_code='S';boom boom pow |
|
|
singularity
Posting Yak Master
153 Posts |
Posted - 2009-08-18 : 09:12:29
|
Maybe this:selectb.item_no,a.fin_year,a.fin_week,b.department,a.soh_unitsfromdim_item b left join rtl_loc_item_dy a on b.item_no = a.item_no and a.fin_day = 7 AND a.com_flag = 'Y'left join dim_control c on a.fin_year = c.last_wk_year AND a.fin_week = c.last_wk_weekleft join dim_location l on l.location= a.location and l.chain_no = 10 AND l.loc_type_code = 'S'where b.department = 11 and b.rms_item_ind = 'Y'; |
 |
|
|
Pilgrim007
Starting Member
2 Posts |
Posted - 2009-08-19 : 10:01:23
|
| Thanks for your help...however using the outer join on rtl_loc_item_dy is what is actually working better than the left joins you recemmending.I asked some people why would they use a table like rtl_loc_item_dy, which is a fact table, instead using a dimenension table? The answer I got, was that "we wanna see" the measures which do not exist, to be returned.for shizzle ma nizzle...lolboom boom pow |
 |
|
|
singularity
Posting Yak Master
153 Posts |
Posted - 2009-08-23 : 23:19:52
|
| A left join is an outer join.Would need some sample data and expected output... |
 |
|
|
|
|
|
|
|