473,406 Members | 2,293 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,406 software developers and data experts.

Searching for a blank field in an SQL statement

Hi, im trying to run an update SQL statement which sets the flag (queryident) to ticked if the track title field in that record is blank. However using '' to indicate a blank field does not work. Any ideas? The statment is below.


Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL ("UPDATE [TRACK] SET [QueryIdent] = True WHERE [Track Title] = ''")
  2.  
Feb 19 '08 #1
5 17424
Stewart Ross
2,545 Expert Mod 2GB
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL ("UPDATE [TRACK] SET [QueryIdent] = True WHERE [Track Title] = ''")
  2.  
Hi. You may have null values in your fields rather than empty strings. As nulls will not be found by testing for string length I have used Nz in the code below to return an empty string if the field is null. It also explicitly test for empty strings using the Len function:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL ("UPDATE [TRACK] SET [QueryIdent] = True WHERE Len(Nz([Track Title])) = 0;"
  2.  
-Stewart
Feb 19 '08 #2
Thanks! All working fine now.

Hi. You may have null values in your fields rather than empty strings. As nulls will not be found by testing for string length I have used Nz in the code below to return an empty string if the field is null. It also explicitly test for empty strings using the Len function:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL ("UPDATE [TRACK] SET [QueryIdent] = True WHERE Len(Nz([Track Title])) = 0;"
  2.  
-Stewart
Feb 19 '08 #3
NeoPa
32,556 Expert Mod 16PB
Testing for Null in SQL is best done using the Is Null construct.
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL ("UPDATE [TRACK] SET [QueryIdent] = True WHERE [Track Title] Is Null;"
If you want to test for (Null or "") then use :
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL ("UPDATE [TRACK] SET [QueryIdent] = True WHERE Nz([Track Title], '') = '';"
The second version is very little different from the previous post. The first is recommended where possible as it runs more efficiently

NB. The quotes within the SQL string are (') rather than ("). I think you understand this already but for anyone else...
Feb 20 '08 #4
Stewart Ross
2,545 Expert Mod 2GB
Testing for Null in SQL is best done using the Is Null construct....
Hi NeoPa. IsNull in this case would leave the potential for table lines which contain truly zero-length strings not being updated, hence the suggested use of Nz instead (copes with both cases, even if one predominates, or is the only situation at present).

-Stewart
Feb 20 '08 #5
NeoPa
32,556 Expert Mod 16PB
Indeed you're right Stewart.
A couple of small points worth noting though :
  1. I was referring to the "Is Null" SQL construct rather than the IsNull() VBA function. This runs faster (as it's a SQL construct) for larger, more complicated queries. Only useful for Null checks though.
  2. My second example was very similar to yours except I excluded the Len() part. This (either of them - using Nz()) is a good example of covering the situation where Nulls OR empty strings must be handled.
I would have to say that, in my experience, it's very rare for tables to allow both empty strings AND nulls.

By the way Stewart, welcome to TheScripts. We've not crossed paths much before, but I've already heard ABOUT you. Keep up the good work.
Feb 20 '08 #6

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

Similar topics

2
by: Mark Davenport | last post by:
Hi, Here's my question: How do I pass a NULL value in a variable to a MySQL DB? Here's an overview of my problem: I have a PHP page that processes code, then inserts the code into a database....
1
by: Keith | last post by:
I am Using Dreamweaver MX to create my site and have come accross a problem no one in the DW groups seems to be able to help with. When I submit an insert to my SQL database, any form value which...
1
by: Joel | last post by:
Hi, How do you determine if a Date field is blank. In my Sql statement I only want records who's date field is blank (i.e. checking for only open invoices where Date_Paid = '' ...still open...
6
by: Andy | last post by:
Hello, I am having many problems with setting up a parameter query that searches by the criteria entered or returns all records if nothing is entered. I have designed an unbound form with 3...
3
by: Paul H | last post by:
I have a text file that contains the following: ******************** __StartCustomerID_41 Name: Fred Smith Address: 57 Pew Road Croydon
4
by: sparks | last post by:
I am trying to fix a database that someone did about 4 yrs ago in access97. The main table just contains demographics and is on the main form of the database. It has a subform on a tab that...
2
by: dcousineau | last post by:
Hi! I'm working with a database of news clippings. The database has fields for the title of the article and the text of the article (also other fields for things like sources and categories, but...
1
by: nickb34 | last post by:
I don't have much experience with VB and I have found Excel's conditional formatting very limited. I need a macro that will search through all the cells and when it finds a blank cell, it needs to be...
4
by: barmatt80 | last post by:
I have created an unbound form so that when users enter the information, there is a save button they have to click, checking to make sure a field(txtDocketNo) is not blank. For some reason I cannot...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
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
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...
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
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...
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
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,...

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.