sql - LEFT join returns only NULL for right side -
i facing problem join
query 2 conditions. problem query gives left site, whereas right site contains null
. checked types of data match. going wrong?
select t2.year_number ,t2.week_number ,t2.stock_ric ,t1.sent_pos_weighted ,t1.sent_neut_weighted ,t1.sent_neg_weighted ,t1.observations ,t1.av_w_relevance ,t1.av_w_lnkd_cnt1 ,t1.av_w_item_cnt1 res structure2016 t2 left join pre t1 on t1.week_number = t2.week_number , t1.stock_ric = t2.stock_ric order stock_ric, week_number
edit: brief example of how tables , should like. stock_ric columns of type char(13)
table structure2016: stock_ric year week_number jpm.n 2016 1 jpm.n 2016 2 jpm.n 2016 3 table pre: stock_ric week_number sent_pos_weighted jpm.n 5 0.1 jpm.n 3 0.9 jpm.n 1 0.1 jpm.n 10 0.1 result should stock_ric week_number sent_pos_weighted jpm.n 1 0.1 jpm.n 2 null jpm.n 3 0.9
it should work fine, constructed sample provided , here result
stock_ric week_number sent_pos_weighted jpm.n 1 0.1 jpm.n 2 null jpm.n 3 0.9
the code used
declare @table table( stock_ric varchar(10), year int, week_number int ) declare @pre table( stock_ric varchar(10), week_number int, sent_pos_weighted decimal(3,1) ) insert @table(stock_ric,year,week_number) select 'jpm.n',2016,1 union select 'jpm.n',2016,2 union select 'jpm.n',2016,3 insert @pre(stock_ric,week_number,sent_pos_weighted) select 'jpm.n',5,0.1 union select 'jpm.n',3,0.9 union select 'jpm.n',1,0.1 union select 'jpm.n',10 ,0.1 select t.stock_ric,t.week_number,p.sent_pos_weighted @table t left join @pre p on t.stock_ric = p.stock_ric , t.week_number = p.week_number
it seems problem not in code posted
Comments
Post a Comment