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 |
pvong
Yak Posting Veteran
58 Posts |
Posted - 2012-03-06 : 15:57:05
|
Sorry for the simple question but I'm trying to learn. Here is an image of my table. Here is my Select Statment SELECT Clients.Autex, Clients.AcctName, AxysPals.QuantityFROM AxysPals INNER JOIN Clients ON AxysPals.Autex = Clients.AutexWHERE (AxysPals.Ticker = 'XYZ')GROUP BY Clients.Autex, Clients.AcctName, AxysPals.QuantityHAVING (Clients.Autex = '6581') OR (Clients.Autex = '6570') OR (Clients.Autex = '6545') OR (Clients.Autex = '6550') What I'm trying to do is get a result where it will show me all four of the Autex and AcctName even if the qty is 0 where Ticker does not exist for XYZ. Something like below. In the below example, 6545 and 6550 does not own any XYZ in the AxysPal table but exist in the Clients table. Autex Name Qty6581 Acct1 1006570 Acct2 2006545 Acct3 <Blank because it does not have XYZ>6550 Acct4 <Blank because it does not have XYZ>I think there's something wrong with my join but I'm not sure. When I run this, I just getAutex Name Qty6581 Acct1 1006570 Acct2 200Thanks!Phil------------------------------Using VS2010 / Learning in VB.Net / Win2008 R2 / SQL 2008 R2Be kind to the newbies because you were once there. |
|
X002548
Not Just a Number
15586 Posts |
|
pvong
Yak Posting Veteran
58 Posts |
Posted - 2012-03-06 : 16:48:57
|
Sorry for the confusion.6545 and 6550 does not have any XYZ in the AxysPals table but I still want them to show up in the result because they exist in the Clients table but I want the QTY to be blank for those two accounts.I updated my original to try and clear it up a little more.------------------------------Using VS2010 / Learning in VB.Net / Win2008 R2 / SQL 2008 R2Be kind to the newbies because you were once there. |
 |
|
pvong
Yak Posting Veteran
58 Posts |
Posted - 2012-03-08 : 10:32:39
|
ANYONE???Please help a newbie out. I'm trying to learn.Thanks!------------------------------Using VS2010 / Learning in VB.Net / Win2008 R2 / SQL 2008 R2Be kind to the newbies because you were once there. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-03-08 : 10:36:44
|
quote: Originally posted by pvong ANYONE???Please help a newbie out. I'm trying to learn.Thanks!------------------------------Using VS2010 / Learning in VB.Net / Win2008 R2 / SQL 2008 R2Be kind to the newbies because you were once there.
SELECT DISTINCT Clients.Autex, Clients.AcctName, AxysPals.QuantityFROM Clients LEFT JOIN AxysPals ON AxysPals.Autex = Clients.AutexAND (AxysPals.Ticker = 'XYZ')WHERE (Clients.Autex IN ('6581','6570','6545','6550') ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
pvong
Yak Posting Veteran
58 Posts |
Posted - 2012-03-08 : 11:14:09
|
visakh16Thanks!! This worked.------------------------------Using VS2010 / Learning in VB.Net / Win2008 R2 / SQL 2008 R2Be kind to the newbies because you were once there. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-03-08 : 11:45:15
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|