how to match null values in JOIN ON - 18128

Hi,

I am working with MS Access.  My tables are:

table1:
var1      var2    cnt
null        1        1
null        2        2
1           1        3
1           2        4
2           1        5
2           2        6

table2:
var1      total
null         3
1            7
2          11

My query is:
SELECT * from table1
left join
(select * from table2) as b
on table1.var1=b.var1

My results are:
var1      var2    cnt   total
null        1        1     null
null        2        2     null
1           1        3       7
1           2        4       7
2           1        5      11
2           2        6      11

I would like 'null' in var1 be treated as a legit level and the total
be 3 instead of null.  Before I go off to make my own join routine, is
there a way I can make the sql work my way?

Thanks in advance,
Jenn

0
jliu1971
10/10/2007 1:49:02 PM
access.queries 6343 articles. 1 followers. Follow

1 Replies
3621 Views

Similar Articles

[PageSpeed] 45

You can use the Nz function to replace Null with a "default" value (in my 
example, I'm using -1 because it doesn't appear in your other data as a 
value for var1) as part of an non-equijoin relationship:

SELECT * from table1
left join
(select * from table2) as b
on Nz(table1.var1, -1)=Nz(b.var1, -1);

-- 

        Ken Snell
<MS ACCESS MVP>





<jliu1971@yahoo.com> wrote in message 
news:1192024142.705876.63390@r29g2000hsg.googlegroups.com...
> Hi,
>
> I am working with MS Access.  My tables are:
>
> table1:
> var1      var2    cnt
> null        1        1
> null        2        2
> 1           1        3
> 1           2        4
> 2           1        5
> 2           2        6
>
> table2:
> var1      total
> null         3
> 1            7
> 2          11
>
> My query is:
> SELECT * from table1
> left join
> (select * from table2) as b
> on table1.var1=b.var1
>
> My results are:
> var1      var2    cnt   total
> null        1        1     null
> null        2        2     null
> 1           1        3       7
> 1           2        4       7
> 2           1        5      11
> 2           2        6      11
>
> I would like 'null' in var1 be treated as a legit level and the total
> be 3 instead of null.  Before I go off to make my own join routine, is
> there a way I can make the sql work my way?
>
> Thanks in advance,
> Jenn
> 


0
Ken
10/10/2007 2:16:44 PM
Reply:

Similar Artilces:

Macro that deletes values with condition
Hi, I need a macro that deletes duplicates of numbers that appear an odd number of times and that deletes duplicates and the value duplicated an even number of times. Example: Original data A 1 2 3 1 2 1 2 3 4 Result: A 1 2 4 Values 1 and 2 must remain and only delete duplicates because they appear an odd number of times (3), 3 must be deleted because it appears an even number of times (2) and 4 appears because it has no duplicates. Hope this can be done! Thank you so much Hi Insert a heading in row 1 and try this macro: Sub aaa() Dim f As ...

Incorrect subtotal when matching an invoice to a PO
Hello, I've recently had trouble when matching an invoice to a PO. It seems that each line item total was correct, but the subtotal was off by the landed cost I had added on to this shipment. I also had problems trying to match another, separate landed cost to this shipment. It seems like this just needs to be reconciled, but I'm not sure how. Please let me know if you have experienced this and what to do. Thanks! Lisa C. ...

view the reference and not the value
Dear All, I am trying to bring in 5 sheets a value (text) from the first sheet. When i typing the equal (=) in the sheet2 i saw the reference and not the value. Any solution for that ? i am using the XP edition Thanks in advance Manos Hi 1. check that your target cell is not formated as 'Text'. change the format to 'General' and re-enter the formula 2. If this does not help goto 'Tools - Options - View' and uncheck 'Formulas' >-----Original Message----- >Dear All, > > >I am trying to bring in 5 sheets a value (text) from the >firs...

use displayed value in calculation
quick question - if I perform a simple calculation of =(a1+b1) in the m1 cell, and then need to use that result in another calculation in the n1 cell =(m1*3.14), why do I get a value of 0.00 returned? michae What values are in cells A1 and B1? A small number, showing two decimal places, could display as 0.00 michael wrote: > quick question - > > if I perform a simple calculation of =(a1+b1) in the m1 cell, and then > need to use that result in another calculation in the n1 cell > =(m1*3.14), why do I get a value of 0.00 returned? > > > > michae > -- ...

Incoming mail for domain not matched to recipient
Is there any way to have all incoming mail for my domain name that does NOT match my recipients be routed to a single user? Thanks! On Mon, 16 May 2005 12:00:48 -0400, "Jack Ingraham" <jack@selectivesoftware.com> wrote: >Is there any way to have all incoming mail for my domain name that does NOT >match my recipients be routed to a single user? > >Thanks! > http://support.microsoft.com/default.aspx?scid=kb;en-us;324021 http://www.aloaha.com/software-development/catch-all-mailbox.php http://turbogeeks.com/products/mailbasket.asp ...

Cannot join on Social Security Num
I have a table that I am trying to add an ID number into from another. The two tables have a Social Security Number that is the only way to link the tables. I am trying to change that I am first doing a select query before the update query When I add both tables to a query and tie them together by the Social Security Num, (regular join, not outer or inner) I get zero records retrieved. There are matching Social Security Nums in both tables though The two SocSecNum fields have input picture clauses 000\-00\-0000;0;_ Both fields in both tables are the same length and input pictures ...

Charting with zeros or DIV/0 values
Hi - this might have an easy solution, but I'm a bit stuck. I've created a spreadsheet for data entry by another party. This data will be entered on a monthly basis and I only want to update it occasionally. So, I have control charts set up with the basic formulae (percent, mean, upper and lower control limits) in there. I was wondering if there was any way to have all of this data in the range of the chart without having the chart bottom out (i.e. plotting zeros). For example, my columns _might_ look something like this: Date.........Total...Defects...%ofDefects...Mean....UCL....

How do you get the maximum value to display in text box form
In a form, if I have 4 text boxes and 3 of them will contain a number. How do you get the maximum value to display in the 4th. I have tried many different things, I can make it work for a single field in a table, but that finds the value through all records. I just want it to display the max value from the numbers on the form, which could be different for various records. You could use something like this as the Control Source of the 4th text box (the underscore is for ease of reading here, and must be removed from the Control Source): =IIf([Field1]>[Field2] And [Field1]>[Field3],...

Finding maximum value
Hello, I want to find the maximum value in a column, but I want to ignore the negative and positive part of the value. Basically, the maximum difference from zero. Example: the maximum value I am looking for will be -0.467. -0.467 0.345 -0.253 0.411 Thanks Ruan One way (array-entered: CTRL-SHIFT-ENTER or CMD-RETURN): =INDEX(A1:A4,MATCH(MAX(ABS(A1:A4)),ABS(A1:A4),FALSE)) In article <OGKhnF1KEHA.2100@TK2MSFTNGP10.phx.gbl>, "Ruan" <ruan@aegismed.com> wrote: > Hello, > > I want to find the maximum value in a column, but I want to ignore the > negati...

Using offset in series values of a chart
I have 1 named range created with the offset function on sheet(1): Month=offset($A$1,0,0,counta($A:$A),1) Simple to use as the x-as categories in a chart. For the y-axis I want to use data which can be offset 1, 2, up to 20 columns. Yes I can create 20 named ranges but to do that for 20 sheets in my workbook gets cumbersome. Therefor my question: Can I use the offset function in the series values, like: =offset(Month,0,7) In VBA it it can be done with: ..SeriesCollection(2).Values = Month.Offset(0, 17) But then I have to create one macro for each graph...again cumbersome. Please help. T...

Determine if Value in column A exists in Column B
Hello All- Simple question...I have a sheet with several hundred 10 digit numbers in column A and in Column B. I need a formula to put in column C, that will tell me if the number in A appears anywhere in the list of column B. Doesn't matter if the num,ber in column A appears more than once in column B, just if it appears anywere at all.. A B C 1 02020 02110 True (appears at B2) 2 01121 02020 False 3 01111 98981 False 4 02110 89789 True (appears at B1) 5 19982 58676 ...

Dual Value Axes advice needed please.
Hi all, need some help with what should be a simple chart. Using Excel 2003, I have a worksheet with a rolling year of data, months on row 1, series titles in A2:A4, values in B2:M4 and Annual Total in Column N (data in N2:N4). As the Annual Total is 12 times the average I want the Total to be assigned to a second Value Axis on the right from the default Value Axis on the left. I have no problem setting a complete Series to a second value Axis, but I want to set a category to the second axis. How can I do that? Thanks. -- Spence To add the secondary category axis, go to Chart menu...

Outlook Email To email address dependent on dropdown value
I have the vba code in my word 2003 form to send an email to a specific address etc. What I want to do is depending upon the value of a specific dropdown field send to a different email address. So, if the value is 1 then send to me@thisemail.com but if the value is 2 then sent to them@thisemail.com. I've looked everywhere on this group and can't find an answer. Could someone help me out please. thanks so much you guys are great! The following should work Sub Send_As_Mail_Attachment() ' send the document as an attachment _ in an Outlook Email message Dim b...

Changing Node Values
I have the following XML.. <?xml version="1.0" encoding="UTF-8"?> <EMS> <Scene> <Number_of_Patients>1212</Number_of_Patients> <MCI code_description_type="description"> <Code>Stri</Code> </MCI> <Location_Type code_description_type="description"> <Code>Stri</Code> </Location_Type> <Service_Type code_description_type="description"> <Code>Stri</Code> </Service_Type> </Scene> </EMS> using the following Xpath expression...

cell to have comma-delimited values based on text
I have a table called "220_reference" with a column name "Part Number" having a sample value of below: 4047122(All Dash no.), 4057222(All Dash no.), 4058222(All Dash no.), 4060122(All Dash no.) The entire value is in one cell representing the "Part Number" column(defined as general type so text I suppose). Simple enough. But what I need to do is take any number that has "(All Dash no.)" after it and search through a column in another table to retrieve any rows that have that number(text) in it. The other table name is "220" with ...

Left Join dilemma is this possible?
I am trying to create a recordset in Excel 2000 from two Access 2000 tables to include all items from the first table "Liquor" and only items from the second table "LiquorOrders" that match either a date or an order number. I have 19 items in the first table and I would like to select all 19 items and only these 19 items with a Status = True, with corresponding data from the "LiquorOrders" with blanks where an order for an item was not placed on that specific date or order number. This at first seemed possible but after much researching and experimentation I hav...

Droping the lowest value
Hi I need a formuls to drop the lowest value and add the rest as in..... Cell (AF4) Cell (AH4) Cell (AJ4) Cell (AL4) Cell (AN4) 100 90 80 70 170 What I want the formula to do is drop the lowest number (70) and then add the rest together (100+90+80) and put the total in Cell (AN4) Thanks in advance.. Keith "Kb" <no@spam.com> wrote in message news:445342d4$0$7528$afc38c87@news.optusnet.com.au... > Hi I need a formuls to drop the lowest value and add the rest as in..... > > Cell (AF4) Cell (A...

criteria default value?
I've created a query that has a from/to criteria as shown below: >=[From Pre-School Number :] And <=[To Pre-School Number :] The possible numeric range is 1-99, so entering 7 and 7 gives you just Pre-School 7's details, or entering 1 and 99 gives you every Pre-School's details. Is there some way to have the "Enter Parameter Value" boxes come up with a default value already in there (say 1 and 99 respectively), which the user can then typeover if they choose. Thanking you in anticipation. You can create an Access Form [frmPreQuery] with 2 Textboxes (defaulted ...

(Advance Programming) Parameter Returned as Value
Hi, I wish some body could Help Me, I have being loocking for a solution for 2 days. I need to make a simple Query to check if the parameter values are in a Table. I want the Query to return "Founds" and "Not Founds". For Example: Table Definition: TName CREATE TABLE [dbo].[TName] ( [IdName] [bigint] IDENTITY (0, 1) NOT NULL , [Name] [nvarchar] (30) COLLATE Traditional_Spanish_CI_AS NOT NULL ) ON [PRIMARY] Values: Insert Into TName (Name) Values ('Paul') Insert Into TName (Name) Values ('Peter') Insert Into TName (Name) Valu...

Outbox Parameter Value Invalid Error
My Gmail is linked to Outlook. Currently, I have a message sitting in the Outbox of email. It won't send after multiple tries, and the error message reads: Task 'Gmail - Sending' reported error (0x80070057) : 'Could not complete the operation. One or more parameter values are not valid.' What does this mean? I am not a very savvy IT person, so layman's terms would be helpful with any offered solutions. Thanks! ...

Require Tax Detail Totals to Match the Pre-Tax Amount in SOP and .
Please incorporate the Require Tax Detail Totals to Match the Pre-Tax Amount functionality into POP and SOP. I created a CR/PR on this and dev informed me this was a product suggestion. This is very important functionality for European clients in terms of producing correct VAT returns. ...

Complete unknown values in series
I have a series of lab values vs age. I can plot them on a graph and a line forms between the values forming a curve though not symetrical. Since age is a constant across the graph from 0 to 120 hours, is there a way to get Excel to predict lab values for specific ages based on the curve generated on the graph by the known values? If so, can someone help me through this? Thank you. you can use <chart><add trendline> to have Excel try to fit your data. If you have a theoretical expected fit (Log, Power, exponential, etc) you can tell excel to fit many of those curves. In ...

Join based on next closest value (like Excel VLOOKUP)
Trying to do something similar to a VLOOKUP (Excel) in an Access 2003 query. I have the following tables: JOBS Job,Quantity A,96 B,256 C,300 D,4299 COSTS Quantity,Cost 0, $1000 100, $1200 200, $1500 300, $2000 400, $2500 500, $3000 I need a query that takes JOBS.Quantity, looks it up in COSTS.Quantity and find the cost for the NEXT LOWEST quantity. (Example: Job B has a quantity of 256 and the next LOWEST quantity from COSTS is 200 so Job B costs $1500.) The results should be as follows: JOBS.Job,COSTS.Cost A,$1000 B,$1500 C,$2000 D,$3000 This would be ...

Question on "Value" function
In trying to use Excel to help solve a mathematical puzzle, I would like to calculate the result of applying the mathematical operator in one cell to the numbers in two other cells. Example: A1 contains 2, B1 contains +, C1 contains 3. In D1, create a formula that will give the result of 2 + 3, i.e. 5. I have tried (among many other attempts) =VALUE(CONCATENATE(A1, B1, C1)), but it gives me a #VALUE! error. What am I missing? Hi this is not possible without using VBA. try the following UDF: Public Function my_calculate(op1 As Range, operand As Range, op2 As Range) my_calculate = Ap...

How do I change X-Axis values in a chart with 2 Y-Axis?
I am attempting to chart two data series that share a X-Axis. The Y-Axis for these series are at different ranges so I have two Y-Axis. When I do this the X-Axis turns into a non-numerical entry, example, 1-2-3-4, when my data is a time and is organized as this (15-30-60-90...etc.) Is there a chart with two Y-Axis and one X-Axis with the plot showing the appropriate spacing that I require? I am using Excel 2002 if that changes anything when You go to <chart><Chart data><series> does it show two different x data sets? if your x axis lables were on the set you chang...