Originally posted by original PM
View Post
- Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
- Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!
Reply to: Damn SQL Joins
Collapse
You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:
- You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
- You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
- If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.
Logging in...
Previously on "Damn SQL Joins"
Collapse
-
And audit type is null......Originally posted by original PM View Postfound out the problem was not the join
it was the where clause which initially said
where print flag = 0 and audit type = 2
needed to add
or printflag = 0 and audit type = NULL
but cheers everyone rep on it is way!
Leave a comment:
-
found out the problem was not the join
it was the where clause which initially said
where print flag = 0 and audit type = 2
needed to add
or printflag = 0 and audit type = NULL
but cheers everyone rep on it is way!
Leave a comment:
-
Well that's the most productive I've been so far todayOriginally posted by WTFH View Posttoo slow - MS is in there already
Leave a comment:
-
Inner isn't left. Move your restriction on the audit table to the join, not the where clauseOriginally posted by original PM View Postzero value in first table (invoice not printed)
there is then going to an audit table - which has multiple rows for each invoice -- however I only want the audit record for the invoice being created
so currently it is
select tblinvoice.invoicenumber, tblaudit.auditdate
from tblinvoice
Inner Join tblaudit on tblinvoice.invoicenumber = tblaudit.invoicenumber
where tblinvoice.printflag = 0 and tblaudit.audittypeid = 2
But generally get 2871 records just looking for invoices with a print flag of 0
but only 2848 when trying the above - which is correct as the missing 23 invoices do not have a record in the audit table as they were created prior to the audit functionality coming on line
:sigh: I could pass it to our dev team but it should be simple so killing some time trying to do it myself!
Code:SELECT tblinvoice.invoicenumber, tblaudit.auditdate FROM tblinvoice LEFT Join tblaudit ON tblinvoice.invoicenumber = tblaudit.invoicenumber AND tblaudit.audittypeid = 2 WHERE tblinvoice.printflag = 0
Last edited by mudskipper; 15 November 2018, 11:32.
Leave a comment:
-
zero value in first table (invoice not printed)
there is then going to an audit table - which has multiple rows for each invoice -- however I only want the audit record for the invoice being created
so currently it is
select tblinvoice.invoicenumber, tblaudit.auditdate
from tblinvoice Inner Join tblaudit on tblinvoice.invoicenumber = tblaudit.invoicenumber
where tblinvoice.printflag = 0 and tblaudit.audittypeid = 2
But generally get 2871 records just looking for invoices with a print flag of 0
but only 2848 when trying the above - which is correct as the missing 23 invoices do not have a record in the audit table as they were created prior to the audit functionality coming on line
:sigh: I could pass it to our dev team but it should be simple so killing some time trying to do it myself!
Leave a comment:
-
It is.Originally posted by original PM View PostDamn...
So this is simple
I have one table and I want to return all records from one table where a value - zero.
I then want to join it to another table but whether there is any data in the other table or not I still want the query to return all records from the first table with just null values if there is no data in the second table...
so thats a left outer join (or left join)
but apparently not
That's probably a thread in its own rightOriginally posted by original PM View Postwhy I am so dumb
Post some sample code, expected results, what you're gettingOriginally posted by original PM View Postwhat am I missing?
Leave a comment:
-
Is the value zero or null in the first table?Originally posted by original PM View PostDamn...
So this is simple
I have one table and I want to return all records from one table where a value - zero.
I then want to join it to another table but whether there is any data in the other table or not I still want the query to return all records from the first table with just null values if there is no data in the second table...
so thats a left outer join (or left join)
but apparently not
why I am so dumb and what am I missing?
Have you a key between them?
What is the relationship - is it one to one, one to many, many to one?
Leave a comment:
-
Damn SQL Joins
Damn...
So this is simple
I have one table and I want to return all records from one table where a value - zero.
I then want to join it to another table but whether there is any data in the other table or not I still want the query to return all records from the first table with just null values if there is no data in the second table...
so thats a left outer join (or left join)
but apparently not
why I am so dumb and what am I missing?Tags: None
- Home
- News & Features
- First Timers
- IR35 / S660 / BN66
- Employee Benefit Trusts
- Agency Workers Regulations
- MSC Legislation
- Limited Companies
- Dividends
- Umbrella Company
- VAT / Flat Rate VAT
- Job News & Guides
- Money News & Guides
- Guide to Contracts
- Successful Contracting
- Contracting Overseas
- Contractor Calculators
- MVL
- Contractor Expenses
Advertisers

Leave a comment: