Click here to Skip to main content
15,884,086 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have 2 tables T1 and T2

I want to link them based on a common field eg TranxID

My condition is if T1.TranxID does not exist on T2 then return the row with a NUll or '' T2.TranxID

Else if T1.TranxID exist on T2 then return row with TranxID

What I have tried:

select OrderNumber, TransactionStatusId,FuelPointGuid,B.InvoiceNo,*
from svc_ilfms_live.dbo.FuelTransaction F
	LEFT JOIN IBS_Platform_Billing_Live.dbo.Billing B ON F.Id = B.TransactionId
	where F.orderNumber like '%KWS%'
	AND F.TransactionDateTime BETWEEN convert(varchar, getdate()-60, 23)+' 00:00:00' AND convert(varchar, getdate(), 23)+' 23:59:59' 
	    AND F.FileSent = 0
	order by F.TransactionDateTime desc
Posted
Comments
Richard Deeming 8-Dec-20 12:38pm    
What's wrong with the query you've tried? A LEFT JOIN will do what you describe - any columns in the output from Billing will be Null if there isn't a matching row.
Member 14370529 8-Dec-20 13:00pm    
Got it thanks
BabyYoda 8-Dec-20 14:03pm    
Agreed. That is the purpose of a LEFT JOIN instead of an INNER JOIN. Is this resolved then?
Herman<T>.Instance 8-Dec-20 16:54pm    
LEFT OUTER JOIN?
Richard Deeming 9-Dec-20 3:27am    
The OUTER keyword is optional. LEFT OUTER JOIN and LEFT JOIN are the same thing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900