October 9, 2009 at 3:28 am
Hi Guys,
OK, pretty new to TSQL as you will discover. I am struggling with this one so any help appriciated.
I have 2 tables as seen below and I am trying to join them. I know salesline has 3 records I am interested in and CUSTINVOICEJOUR as 3 related records but one of them has no salesid.
As I understand it the query using the left outer join should bring back 3 records and just have null values in any column that is has no data in the salestable. Please advise, appricaite your time
Jason
SELECT *
FROM CUSTINVOICEJOUR
LEFT OUTER JOIN SALESLINE ON SALESLINE.SALESID = dbo.CUSTINVOICEJOUR.SALESID
WHERE CUSTINVOICEJOUR.DATAAREAID = 'GAL'
AND SALESLINE.DATAAREAID = 'GAL'
AND CUSTINVOICEJOUR.invoiceaccount = 'sa13039'
October 9, 2009 at 3:40 am
Try this
SELECT *
FROM CUSTINVOICEJOUR
LEFT OUTER JOIN SALESLINE ON SALESLINE.SALESID = dbo.CUSTINVOICEJOUR.SALESID
and SALESLINE.DATAAREAID = 'GAL'
WHERE CUSTINVOICEJOUR.DATAAREAID = 'GAL'
AND CUSTINVOICEJOUR.invoiceaccount = 'sa13039'
The where clause is processed after the join and filtering out the null values
October 9, 2009 at 8:02 am
Dave has supplied the answer. Not to pimp my blog, but I recently blogged about this issue and the post may help you, http://wiseman-wiseguy.blogspot.com/2009/09/on-vs-where.html
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
October 9, 2009 at 12:09 pm
October 9, 2009 at 1:17 pm
Garadin (10/9/2009)
"pimp my blog". Nice. :w00t:
I'm not sure what else to call it when I reference my own blog. I feel kind of dirty doing it, but I think it's a good post and it applies.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
October 9, 2009 at 1:28 pm
Garadin (10/9/2009)
--------------------------------------------------------------------------------
"pimp my blog". Nice.
Jack Corbett (10/9/2009)
I'm not sure what else to call it when I reference my own blog. I feel kind of dirty doing it, but I think it's a good post and it applies
And it is a good answer to the OP's question and an easy read ... be proud of it, no need to pimp it just say "read this item"
October 9, 2009 at 3:36 pm
Jack Corbett (10/9/2009)
Garadin (10/9/2009)
"pimp my blog". Nice. :w00t:I'm not sure what else to call it when I reference my own blog. I feel kind of dirty doing it, but I think it's a good post and it applies.
Indeed, I don't know why you'd feel dirty at all. That's the entire purpose of a technical blog. The fact that you are writing things that will actually help people should make you feel better about the time you spend doing it. After all, it's only if nobody benefits from your blog or reads these articles you write that it's truly a waste of time. I just liked the phrase =).
October 9, 2009 at 3:49 pm
Thanks for the support guys. I'm just uncomfortable with self-promotion. Of course, until I have 1000's of readers I guess I have to.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
October 9, 2009 at 5:46 pm
Jack Corbett (10/9/2009)
..until I have 1000's of readers I guess I have to.
Count me in Jack ๐
Piotr
...and your only reply is slร inte mhath
May 23, 2011 at 4:50 am
Sorry for bringing an old thread back to the top but this is a really useful thread. The information gleaned from reading is most helpful. Many thanks.
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply