SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Not in Joining
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

peace
Constraint Violating Yak Guru

410 Posts

Posted - 01/15/2013 :  10:11:21  Show Profile  Reply with Quote
How can I get those balance of list which not in the joining where condition?

select x.Number
,y.currencyCode,y.chargeAmount
into #withAAAchargecode
from tableA x
left join tableB y
on x.passengerid=y.passengerid
where chargecode = 'AAA'

As above, I only pull those Number which has chargecode = 'AAA'

How can I pull the remaining Number in tableA which haven't pull out?

James K
Flowing Fount of Yak Knowledge

3651 Posts

Posted - 01/15/2013 :  10:23:14  Show Profile  Reply with Quote
If chargecode is in tableB, insert that filter on chargecode in the JOIN instead of in the WHERE clause
select x.Number
,y.currencyCode,y.chargeAmount
into #withAAAchargecode
from tableA x
left join tableB y
on x.passengerid=y.passengerid
AND chargecode = 'AAA'
Go to Top of Page

theboyholty
Posting Yak Master

United Kingdom
221 Posts

Posted - 01/15/2013 :  10:25:38  Show Profile  Visit theboyholty's Homepage  Reply with Quote
It depends largely on which table the chargecode field comes from.
I'm going to assume its coming from tableB.

select x.Number,y.currencyCode,y.chargeAmount
into #withAAAchargecode
from tableA x
left join tableB y on x.passengerid=y.passengerid and y.chargecode = 'AAA'
where y.passengerid is null


---------------------------------------------------------------------------------
http://www.mannyroadend.co.uk A Bury FC supporters website and forum
Go to Top of Page

peace
Constraint Violating Yak Guru

410 Posts

Posted - 01/15/2013 :  10:39:15  Show Profile  Reply with Quote
owh..understood now.

Thanks!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000