473,664 Members | 3,022 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Filtering Queries that use a fucntion to return a value (Null Values in a Date Datatype)

Ken
I wrote a function to use in queries that takes a date and adds or
subtracts a certain length time and then returns the new value. There
are times when my function needs to return Null values.

Function DateCalc (blah...) As Variant
Do Stuff...
If Not IsNull(varNewDa te) Then
DateCalc = varNewDate
End If
End Function

Then in a query - MyDate: DateCalc([Blah], [Blah], [Blah])

The results of this are in MyDate are left justified dates with a few
blank rows where the function returns a null value.

I can't filter the results on "Not Is Null", so I changed things a
bit:

MyDate: Nz(DateCalc([Blah], [Blah], [Blah]), "")

And using the criterion <> "". This seems like it will work, (I can
see the rows get populated and there are no rows with blanks), but at
the end there is an error message: Date type mismatch in criterion
expression. Then all of the cells in the results are filled with
"#Name?".

I even tried CStr(Nz(DateCal c([Blah], [Blah], [Blah]), "")), but got
the same results.

So next I changed the datatype of the funtion to Date, specified that
all the rows that would have returnd Null return "08/08/1888" (not
optimal, I know), and then running the query.

MyDate: DateCalc([Blah], [Blah], [Blah])
<>#08/08/1888#

It also looked like it would run fine, but at the end I got the same
error message about a data type mismatch in the criterion expression.

Finally, I tried querying my first query and using criterion in the
second query instead of using a criterion in my user defined function
field, but that also gave the data type mismatch error.

I don't know if it matters, but the MDB files reside on a Samba server
network.

What principles about functions and using them in queries and dealing
with Null values do I need to understand to overcome this problem?
Any suggestions?

Thanks!
Nov 12 '05 #1
1 1194
== Reply at bottom ==

Ken wrote:
I wrote a function to use in queries that takes a date and adds or
subtracts a certain length time and then returns the new value. There
are times when my function needs to return Null values.

Function DateCalc (blah...) As Variant
Do Stuff...
If Not IsNull(varNewDa te) Then
DateCalc = varNewDate
End If
End Function

Then in a query - MyDate: DateCalc([Blah], [Blah], [Blah])

The results of this are in MyDate are left justified dates with a few
blank rows where the function returns a null value.

I can't filter the results on "Not Is Null", so I changed things a
bit:

MyDate: Nz(DateCalc([Blah], [Blah], [Blah]), "")

And using the criterion <> "". This seems like it will work, (I can
see the rows get populated and there are no rows with blanks), but at
the end there is an error message: Date type mismatch in criterion
expression. Then all of the cells in the results are filled with
"#Name?".

I even tried CStr(Nz(DateCal c([Blah], [Blah], [Blah]), "")), but got
the same results.

So next I changed the datatype of the funtion to Date, specified that
all the rows that would have returnd Null return "08/08/1888" (not
optimal, I know), and then running the query.

MyDate: DateCalc([Blah], [Blah], [Blah])
<>#08/08/1888#

It also looked like it would run fine, but at the end I got the same
error message about a data type mismatch in the criterion expression.

Finally, I tried querying my first query and using criterion in the
second query instead of using a criterion in my user defined function
field, but that also gave the data type mismatch error.

I don't know if it matters, but the MDB files reside on a Samba server
network.

What principles about functions and using them in queries and dealing
with Null values do I need to understand to overcome this problem?
Any suggestions?


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I ran across a similar problem today (same error, but different set up).

I had one query that used DateAdd() function to increment a Date column
value by 30 days. Sometimes the date value was NULL. Running query 1 -
everything came out as expected: Null Date columns return null results
& valid dates were incremented correctly.

But, when I incorporated query 1 into query 2 - when a NULL Date value
was processed by the DateAdd() & passed to query 2 the type mismatch
error occurred.

I finally used DateColumn + 30 instead of DateAdd("d", 30, DateColumn).
The error disappeared & query 2 worked as expected.

I figured NULL was somehow discombobulatin g the DateAdd() function, and
I knew that a NULL + integer would result in NULL, which is what I
wanted passed to query 2.

--
MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQHSzoYechKq OuFEgEQJNOACdFu bY0lhbwv4eD5LVN HnBGf+1T/cAnR1/
SiYxk6bEyGRD2Xy zybrQoHWD
=lK/o
-----END PGP SIGNATURE-----

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1388
by: Nick Truscott | last post by:
Is this possible? I have a form which asks the user to input the result of a soccer match. I want to then use a choice of three sets of queries (Home Win, Away Win, Draw) to update two tables, Matches (the master list of all matches and there results) and Teams (a list of all teams with total numbers of matches played, won, lost drawn etc?)
0
1497
by: Skip Montanaro | last post by:
Consider the output of these two explain statements: mysql> explain select count(*) from cities,addresses,venues,events where cities.latitude <= 30.2741903768 and cities.latitude >= 30.2596976232 and cities.longitude <= -97.734387326 and cities.longitude >= -97.751168674 and events.venue = venues.id and venues.address = addresses.id
1
2477
by: Alex Satrapa | last post by:
I have a table from which I'm trying to extract certain information. For historical reasons, we archive every action on a particular thing ('thing' is identified, funnily enough, by 'id'). So the only way to find out the current state of a particular combination of attributes is to "select distinct on (id, ...) ... order by date desc". In the examples below, I've taken real output from psql and done a global search/replace on various...
13
5890
by: Anton.Nikiforov | last post by:
Hello everybody! Does someone know how to build hierarchical queries to the postgresql? I have a table with tree in it (id, parent) and need to find a way from any point of the tree to any other point. And i would like to have a list of all steps from point A to point B to make some changes on each step (this is required by the algorythm). Here is an example:
1
2471
by: Ken | last post by:
I wrote a function to use in queries that takes a date and adds or subtracts a certain length time and then returns the new value. There are times when my function needs to return Null values. Function DateCalc (blah...) As Variant Do Stuff... If Not IsNull(varNewDate) Then DateCalc = varNewDate End If End Function
4
3552
by: John Smith | last post by:
Isn't life a bitch! You know what you want but you don't know how to get it. I have produced 12 queries that calculate a payment profile over 12 months. For a number of the records (ie with the same product id)there are likely to be more than one payment recorded. Nonetheless, when I run the queries individually and the query relates to a table that provides referential integrity through a one to many relationship, the query does what...
7
14802
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I want to look at that data and filter it based on what is in it. I know that this could have been done with data sets and data views in asp.net 1.1 but how is this done now in asp.net 2.0?
3
18633
by: Liam Mac | last post by:
Hi All, Can anyone direct me or provide advice on how I can assign a null value to a date variable in vb.net. Basically what I'm doing is that I'm looping through a recordset where I have three date fields that may or maynot have date values, if no date values exists in the source field, the value is null. but when I pass a record from the recordset to SQL command parameter query for record insertion into a different table, the date...
2
1606
Spazasaurus
by: Spazasaurus | last post by:
I am having trouble. I am not sure if it is not possible or not, but don't know any alternatives. I am converting my site from PHP and MYSQL to ASP.NET and MSSQL. In my current site. I did a query and then did another query on each record while looping through those results to get what I am trying to do in one query now. I would simply do that same thing but I am not sure how while using Visual Studio and I know that it was bad code, so...
0
7662
MMcCarthy
by: MMcCarthy | last post by:
Rather than using the Access design view change the view to SQL. I am going to attempt to outline the general syntax used for SQL queries in Access. Angle brackets <> are used in place of some syntax elements you must supply. The description of these elements will be in the contained in the angle brackets. Square brackets are used to show which parts are optional. Basic SELECT query SELECT <field list> FROM <table/query name(s)>
0
8437
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8861
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8778
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8636
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7375
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6187
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5660
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1759
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.