Issue with Inner and Left Join -



Issue with Inner and Left Join -

i writing query combines columns 2 different tables. reading info csv file , doing info reconcilliation. fields follows allow phone call both tables creditors , takers. creditors db has credit name, trade_acct_number, 2 distinct identifiers called trade_id , action_id. takers table on other hand has corresponding trading_account_num , it's 2 distinct identifiers trade_id , action_id.

here conditions; records matched on trading_acct_numbers. based on trading_account_num farther filter info based on trade_id , action_id. trade_id's 8 characters long; if there match on lastly 6 characters of trade_id reflect data; else check action_id.

here current query (written in sql server ce)

select cr.credit_name, tk.trade_acct_num, cr.credit_reg_num, tk.trade_id, tk.action_id [taker] tr inner bring together [creditor] cr on tr.trade_acct_num = cr.trade_acct_num substring([trade_id],3,8) = substring([trade_id],3,8) or tr.action_id = cr.action_id order bt tr.trade_acct_num

currently table have next issues. 90% of desired output matches rows takers table omitted totally. there match based on business relationship number trade_id null action_id causes row not outputted. there no outputs when there match on both trade_acct_num , action_id not trade_id. tried doing left bring together followed inner bring together did not help situation. please help , explain. thanks

a left bring together provide null values creditor fields. need allow possibility of nulls in trade_id or credit_id in joined creditors table. mike mentioned above, illustration info helpful.

select cr.credit_name, tr.trade_acct_num, cr.credit_reg_num, tr.trade_id, tr.action_id [taker] tr inner bring together [creditor] cr on tr.trade_acct_num = cr.trade_acct_num substring(tr.trade_id,3,8) = case when cr.trade_id null substring(tr.trade_id,3,8) else substring(cr.trade_id,3,8) end or tr.action_id = case when cr.action_id null tr.action_id else cr.action_id end order bt tr.trade_acct_num

this checking cr.trade_id null , if so, homecoming tr.trade_id evaluate true , go on test credit_id in same way.

join

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -