Hi all,
I am trying to get this query right, but so far no joy...
I have written the following code in the Field box of the QBD grid of
a query:
firstvalue:IIf(Not (IsNull([Value1])),[Value1],(IIf(Not
(IsNull([Value2])),[Value2],(IIf(Not
(IsNull([Value3])),[Value3],[Value4])))))
What I actually want in field "firstvalue" is the left most value of
Value1, Value2, Value3 and Value4. E.g If for a record Value1 = 0 (or
NULL), then it must return Value2 or Value3 or Value4, depending on
the first one which is not 0 (or NULL).
I keep getting syntax errors, and specifically pointing to the first
comma in the code.
Can somebody please tell me what is wrong? I can email a sample DB to
someone if they want to check out the table which the query is based
on.
Thanks a bunch, in advance!
JP 4 1781
On 5 Aug 2004 01:04:12 -0700, je**********@hotmail.com (Jean) wrote:
Proceed like this, so you can maintain your sanity. Don't try to write
the statement at once, but in several passes. In this example I'm
using "x" as a placeholder for future work.
Use Nz to convert both 0 and null values to 0.
If the Nz=0, do something I'll specify later, else return Value1:
FirstValue: iif(Nz(Value1)=0,x,Value1)
'Here I'm filling in "x" for the second pass.
FirstValue: iif(Nz(Value1)=0,iif(Nz(Value2)=0,x,Value2),Value1 )
You do the third and 4th pass, exactly the same way.
-Tom. Hi all,
I am trying to get this query right, but so far no joy...
I have written the following code in the Field box of the QBD grid of a query:
firstvalue:IIf(Not (IsNull([Value1])),[Value1],(IIf(Not (IsNull([Value2])),[Value2],(IIf(Not (IsNull([Value3])),[Value3],[Value4])))))
What I actually want in field "firstvalue" is the left most value of Value1, Value2, Value3 and Value4. E.g If for a record Value1 = 0 (or NULL), then it must return Value2 or Value3 or Value4, depending on the first one which is not 0 (or NULL).
I keep getting syntax errors, and specifically pointing to the first comma in the code.
Can somebody please tell me what is wrong? I can email a sample DB to someone if they want to check out the table which the query is based on.
Thanks a bunch, in advance!
JP je**********@hotmail.com (Jean) wrote in message news:<7e*************************@posting.google.c om>... Hi all,
I am trying to get this query right, but so far no joy...
I have written the following code in the Field box of the QBD grid of a query:
firstvalue:IIf(Not (IsNull([Value1])),[Value1],(IIf(Not (IsNull([Value2])),[Value2],(IIf(Not (IsNull([Value3])),[Value3],[Value4])))))
What I actually want in field "firstvalue" is the left most value of Value1, Value2, Value3 and Value4. E.g If for a record Value1 = 0 (or NULL), then it must return Value2 or Value3 or Value4, depending on the first one which is not 0 (or NULL).
I keep getting syntax errors, and specifically pointing to the first comma in the code.
Can somebody please tell me what is wrong? I can email a sample DB to someone if they want to check out the table which the query is based on.
Thanks a bunch, in advance!
JP
HI:
Try to past the following into the SQL view window.
DO NOT INCLUDE ANY NEW LINE MARKERS. The following
is all on one line. ( maybe that is where you had the problem )?
Assumed Table name = T
Assuemd Table Fields: named Value1, Value2, etc.
SELECT IIf(Not (IsNull(T.[Value1])),T.[Value1],(IIf(Not
(IsNull(T.[Value2])),T.[Value2],(IIf(Not
(IsNull(T.[Value3])),T.[Value3],T.[Value4]))))) AS firstvalue
FROM T;
I tested this on Access 97 and it returned the
expected value. However, if you wanted something
other than the complete field value, that is another
fish to fry
John je**********@hotmail.com (Jean) wrote in message news:<7e*************************@posting.google.c om>... Hi all,
I am trying to get this query right, but so far no joy...
If you still have trouble after applying Tom's advice, try placing the
following code in a module:
Public Function GetFirst(var1 As Variant, var2 As Variant, var3 As
Variant, var4 As Variant) As Variant
GetFirstValue = 0
If Nz(var1) <> 0 Then
GetFirst = var1
ElseIf Nz(var2) <> 0 Then
GetFirst = var2
ElseIf Nz(var3) <> 0 Then
GetFirst = var3
ElseIf Nz(var4) <> 0 Then
GetFirst = var4
End If
End Function
Then:
SELECT GetFirst([Value1],[Value2],[Value3],[Value4]) AS FirstValue
FROM tblValues;
James A. Fortune
Thanks for all the help everyone! I actually sorted this one out late
yesterday afternoon. :)
The problem I had was that I am using a German version of MS Access,
and somehow it did not understand the term Iif ("Wenn" in German).
I used this statement in the field box of the QBD grid:
firstvalue: Wenn(nz([value1])<>0;[value1];Wenn(nz([value2])<>0;[value2];Wenn(nz([value3])<>0;[value3];[value4])))
Strange, cause it can translate other terms, like Nz, True, IsNull
etc.
Well I got it to work now and would like to thank you all for being so
kind in helping me.
Regards,
Jean ja******@oakland.edu (James Fortune) wrote in message news:<a6**************************@posting.google. com>... je**********@hotmail.com (Jean) wrote in message news:<7e*************************@posting.google.c om>... Hi all,
I am trying to get this query right, but so far no joy...
If you still have trouble after applying Tom's advice, try placing the following code in a module:
Public Function GetFirst(var1 As Variant, var2 As Variant, var3 As Variant, var4 As Variant) As Variant GetFirstValue = 0 If Nz(var1) <> 0 Then GetFirst = var1 ElseIf Nz(var2) <> 0 Then GetFirst = var2 ElseIf Nz(var3) <> 0 Then GetFirst = var3 ElseIf Nz(var4) <> 0 Then GetFirst = var4 End If End Function
Then:
SELECT GetFirst([Value1],[Value2],[Value3],[Value4]) AS FirstValue FROM tblValues;
James A. Fortune This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: dogu |
last post by:
Noob alert.
Code is below.
File is saved as a .php.
What I'm trying to do:
User uses 'select' box drop down list to pick a value.
Value ($site) is derived from a db query. This works fine....
|
by: shank |
last post by:
1) I'm getting this error: Syntax error (missing operator) in query
expression on the below statement. Can I get some advice.
2) I searched ASPFAQ and came up blank. Where can find the "rules"...
|
by: carverk |
last post by:
Hello All
I'm in the middle of moving a MS Access DB to a MySql backend.
I have figured out about 90% of the problems I have faced, execpt
for this one.
I have 3 Queries, which pull records...
|
by: Norm |
last post by:
I have run into problems from time to time (and this is
one of those times) using visual basic to access an
external database and perform a basic select from
statement. When the table is extremely...
|
by: Martin Lacoste |
last post by:
Ok, before I headbutt the computer... don't know why when I add
criteria in a query, I get an 'invalid procedure call'. I also don't
know why after searching the help in access, the various access...
|
by: Stan |
last post by:
I am working with Access 2003 on a computer running XP. I am new at
using Access. I have a Db with a date field stored as mm/dd/yyyy. I
need a Query that will prompt for the month, ie. 6 for...
|
by: gerbski |
last post by:
Hi all,
I am relatively new to ADO, but up to now I got things working the way
I wanted. But now I've run into somethng really annoying.
I am working in MS Access. I am using an Access...
|
by: webhead74 |
last post by:
Hi,
I'm having intermittent problems with queries from my php script to a
postgresql database.
I have a form where I can enter a search query - for instance a last
name. This leads to a...
|
by: ARC |
last post by:
Hello all,
So I'm knee deep in this import utility program, and am coming up with all
sorts of "gotcha's!".
1st off. On a "Find Duplicates Query", does anyone have a good solution for...
|
by: Bob Darlington |
last post by:
The following query opens slowly the first time it is opened (6-7 seconds),
but then is less than one second for the next random number of openings
before slowing (6-7 seconds) again.
SELECT...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |