473,397 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

MS Access SQL (Not Equal To)

elak6
21
I am trying to write a query that checks whether certain criterias are met in new data that i am importing and based on different conditions which are explained below it then displays a text :

1ST CONDITION: If the Internal Part Number and Revision match that of a pre-existing table in the database then the text displays: In The Database

2ND CONDITION: If the Internal Part Number matches but the Revision does not match that that of the pre-existing table in the database then the text displays : Revision Change

3RD CONDITION: If the Internal Part Number and the Revision does not match that of the pre-existing table in the database then the text displays : Not In The Database

This is the sql that i wrote to help execute this,it works for the first condition but it does not work in the second condition at all
The CM52 Parts is table that i am importing new data into whilst the Details Table already exists (The table that holds all my pre-existing data)

Expand|Select|Wrap|Line Numbers
  1. IIf([CM52Parts].[Internal Part Number]=[Details].[Internal Part Number] 
  2. And [CM52Parts].[Revision] Is Null Or Not [Details].[Revision],"Revision Change.",
  3. IIf([CM52Parts].[Internal Part Number]=[Details].[Internal Part Number] 
  4. And [CM52Parts].[Revision]=[Details].[Revision]," In Database.","Not In Database.")) 
  5. AS DisplayText,
For some weird reason for conditions when the internal part number match and the revision does not match it displays Not In Database instead of Revision Change

I have tried a variety of options but none seem to work..
P:S:I am not using a Nz operator because none of my data invloves null values

Any assistance you can offer would be much appreciated
Mar 16 '12 #1
7 6810
MikeTheBike
639 Expert 512MB
Hi

I think I might try it this way
Expand|Select|Wrap|Line Numbers
  1. IIf([CM52Parts].[Internal Part Number]<>[Details].[Internal Part Number],"Not In Database.",
  2. IIf([CM52Parts].[Revision]=[Details].[Revision],"In Database","Revision Change."))

MTB
Mar 16 '12 #2
elak6
21
Hi Mike,

I just tried it and it isnt working.
For parts that dont have matching internal part number and matching revision, it displays Revision Change instead of Not in database

Thanks for helping me
Mar 16 '12 #3
NeoPa
32,556 Expert Mod 16PB
Your tests look totally illogical to me. Why display "Revision Change" in any situation where [Revision] is False? I suspect the results are exactly as would be expected in the circumstances (You share no details of the data so we can only guess).

Also, you have no parentheses to encapsulate your comparison values, so the order of precedence (And is evaluated before Or) may be somewhat different from what you intend. Not as big a problem as comparing the wrong way around, but still worth dealing with to avoid gotchas.
Mar 16 '12 #4
NeoPa
32,556 Expert Mod 16PB
Elak6:
P:S:I am not using a Nz operator because none of my data invloves null values
If this is true then why is line #2 testing for Null?

I would expect line #2, as it's written incorrectly as far as I can see - The Or matches both the previous tests and not just the Null check on the same line, to cause the string "Revision Change" to result in cases where it shouldn't rather than the other way around (as you seem to be reporting). I'll leave this with you.
Mar 16 '12 #5
Mihail
759 512MB
I agree with NeoPa (#14) about parentheses.

Do you ever heard about Divide et Impera ?
So you can define in your query as many column as you need to calculate partial results then other partial results by used first of columns then... until you can easy (and safely) calculate the final result.

So use the new columns as you use sub procedures in VBA.

More, you can define other queries to do that partial jobs.

Of course that approach will slow down a little bit your program so is your choice.
Mar 17 '12 #6
Stewart Ross
2,545 Expert Mod 2GB
I suspect that at least part of your difficulty stems from line 2 of your first post, where you have written

[CM52Parts].[Revision] Is Null Or Not [Details].[Revision]

I think you meant

[CM52Parts].[Revision] Is Null Or [CM52 Parts].[Revision]<>[Details].[Revision]

Anyway, rewriting the nested IIFs and using Nz to guard the Revision field against null values you could try:

Expand|Select|Wrap|Line Numbers
  1. IIf([CM52Parts].[Internal Part Number]=[Details].[Internal Part Number], 
  2.      IIf(Nz([CM52Parts].[Revision])=Nz([Details].[Revision]),"In Database","Revision Change"), 
  3.     "Not in Database")
Not sure why you mention that the values are not null when from your own post Revision may well be, but it's no problem to deal with it.

-Stewart
Mar 17 '12 #7
' pseudo code: let
Expand|Select|Wrap|Line Numbers
  1. cm52iP = [CM52PARTS].[[INTERNAL PARTS]
  2. cm52Rv = [CM52PARTS].[REVISION]
  3. dtiP = [DETAILS].[INTERNAL PARTS]
  4. dtRv = [DETAILS].[REVISION]
  5.  
  6. If((cm52iP = dtiP) && ((cm52Rv = null) || (cm52Rv <> dtRv))) Then
  7. print "Revision change."
  8.  
  9. Else if((cm52iP = dtiP) && (cm52Rv = dtRv)) Then
  10. print "In database."
  11.  
  12. else
  13. print "Not in database."
  14.  
  15. End if
' i hope it helps.. =)
Mar 17 '12 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Porthos | last post by:
Are there 'Null' and 'not equal to' operator that I can use in xsl:if statements? I assume that there must be, but I can't figure out the syntax. For example: <xsl:if test="@title DOES NOT...
7
by: ale.of.ginger | last post by:
Another question: I am writing a sudoku solving program. The 'solving' part of is just multiple iterations. It will take random numbers and keep switching it all around until a set of logic...
1
by: dmkeith2 | last post by:
I have a sub report that I place in another report. When I do this I have to specify the Child and Master IDs. I would like the data from the subreport to only show the personnel that are not...
1
by: Glenn Roberts | last post by:
Hi, I've been using CodeDom to generate and compile source code... .....but, have found that in the CodeBinaryOperatorType (used when making a CodeBinaryOperatorExpression), there is no "not...
7
by: Piper707 | last post by:
Hi, I need to know how I can check to see if a particular node is NOT equal to a SET of values. i.e. a valid form of : <xsl:template match!="H" && match!="Y"&& match!="Z"> I have an XML...
4
by: ooroboo | last post by:
i am doing a very small project to get used to using vb6 but, i am stuck i wont a dialog box to appear when the text is not equal to what i wont it to be . I hope it will make more sense after my...
2
by: vitaminz | last post by:
Hi, I'm currently coding a Java program for a University coursework, and I'm a little bit stuck. How do I find out if a string is NOT equal to a certain value? I know to test if it is equal, you...
1
by: deshaipet | last post by:
Hi friends - I created a automatic storage tablespace with a pagesize of 16 K and initial size of 64 MB. create large tablespace test_tbsp1 pagesize 16k managed by automatic storage autoresize...
3
by: DEAbhishekBUG | last post by:
sir i am a student and i always want to learn more i replied for the question -how-do-i-say-not-equal-more-than-one-number my reply was 1> if given variable is either not equal to 1 or 2 you need...
6
by: Colin Kepl | last post by:
In Access, I have a table that receives data from Excel. I have a second table that has one of its fields changed based on a comparison to the first table. The update query is as follows: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.