If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > IS NULL query problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-14-05, 07:09
donaldt donaldt is offline
Registered User
 
Join Date: Jan 2002
Location: Nottingham - UK
Posts: 113
IS NULL query problem

Hi Folks - a little problem thats baffling me......

Im using SQL 2000 db

Im querying a field using 'IS NULL' as the criteria, if I add data to the field and then delete and then try to query using 'IS NULL' as the criteria then the record will not be returned in my query even though the fields empty......

Can anyone help please ?

Thanks in advance

DOnald
Reply With Quote
  #2 (permalink)  
Old 12-14-05, 07:26
ivon ivon is offline
Registered User
 
Join Date: Nov 2002
Posts: 272
Is the field really empty (NULL)? Or is there an empty string now? They are different in SQL Server.
Reply With Quote
  #3 (permalink)  
Old 12-14-05, 07:30
donaldt donaldt is offline
Registered User
 
Join Date: Jan 2002
Location: Nottingham - UK
Posts: 113
IS NULL Problem

Hi - in the database it shows as an empty string (nothing in it!)

So I need the criteria to query IS NULL and an empty field if that makes sense......

Any idea's... ?

Thanks for the quick reply !

Donald
Reply With Quote
  #4 (permalink)  
Old 12-14-05, 07:35
ivon ivon is offline
Registered User
 
Join Date: Nov 2002
Posts: 272
SELECT *
FROM yourTable
WHERE yourField IS NULL OR yourField = ''

should do the trick.
Reply With Quote
  #5 (permalink)  
Old 12-14-05, 07:37
donaldt donaldt is offline
Registered User
 
Join Date: Jan 2002
Location: Nottingham - UK
Posts: 113
Sorted !

Many thanks it worked !
Reply With Quote
  #6 (permalink)  
Old 12-14-05, 10:38
donaldt donaldt is offline
Registered User
 
Join Date: Jan 2002
Location: Nottingham - UK
Posts: 113
ASP Query

The worked fine in SQL, but not using VB / ASP....

Here's the string of code that im having problems with;

<%If BecamePartAss <> "" or not isnull(BecamePartAss) then%>

The above works fine if the field 'IS NULL', but when an empty string exists then your code does not - as below;

SELECT *
FROM yourTable
WHERE yourField IS NULL OR yourField = ''

Thsi may be out of your realm here, but would like you to take a look if you can ?

Regards

Donald
Reply With Quote
  #7 (permalink)  
Old 12-14-05, 12:35
ivon ivon is offline
Registered User
 
Join Date: Nov 2002
Posts: 272
I'm sorry; I'm not that good at VBScript.
Hopefully someone else can help you with that.
Reply With Quote
  #8 (permalink)  
Old 12-14-05, 13:06
Teddy Teddy is offline
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,075
how are you connecting exactly?

Try WHERE ISNULL(yourField, "") = ""
__________________
oh yeah... documentation... I have heard of that.

*** What Do You Want In The MS Access Forum? ***
Reply With Quote
  #9 (permalink)  
Old 12-14-05, 13:16
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
When you want to "empty" a column, can't you just assign it a NULL value instead of using an empty string? That sure sounds like the best long term answer to me.

-PatP
Reply With Quote
  #10 (permalink)  
Old 12-15-05, 04:10
donaldt donaldt is offline
Registered User
 
Join Date: Jan 2002
Location: Nottingham - UK
Posts: 113
Assign Null Value

Hi - that sounds the best course of action, would you have any information on how to do this ?

Thanks

Donald
Reply With Quote
  #11 (permalink)  
Old 12-15-05, 14:37
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Please post the code you're using to assign an empty string, and I'll gleefully modify it to use a NULL instead.

-PatP
Reply With Quote
  #12 (permalink)  
Old 12-16-05, 04:34
donaldt donaldt is offline
Registered User
 
Join Date: Jan 2002
Location: Nottingham - UK
Posts: 113
The Code

Hi Pat - below is the line of code that has the query in thats not working, I have also attached the page.

The code is at line 225 on teaminfo.asp

<%If BecamePartAss <> " " or not isnull(BecamePartAss) then%>

Its an SQL 2000 db, and the field is varchar 50

This problem has come about I have entered text in the field and then deleted, then when I query looking for nulls it does not see an 'empty string'...

Many thanks for taking time to help.

Donald
Attached Files
File Type: zip teaminfo.zip (2.3 KB, 31 views)
Reply With Quote
  #13 (permalink)  
Old 12-16-05, 04:56
ivon ivon is offline
Registered User
 
Join Date: Nov 2002
Posts: 272
Quote:
Originally Posted by donaldt
<%If BecamePartAss <> " " or not isnull(BecamePartAss) then%>
This problem has come about I have entered text in the field and then deleted, then when I query looking for nulls it does not see an 'empty string'...
Your code doesn't check for empty string. It checks for a string containing a space.
Reply With Quote
  #14 (permalink)  
Old 12-16-05, 04:59
donaldt donaldt is offline
Registered User
 
Join Date: Jan 2002
Location: Nottingham - UK
Posts: 113
Hi Ivon

Quote:
Originally Posted by ivon
Your code doesn't check for empty string. It checks for a string containing a space.
I tried it like tis too;

<%If BecamePartAss <> "" or not isnull(BecamePartAss) then%>

Can you tell me where im going wrong.... ?

Donald
Reply With Quote
  #15 (permalink)  
Old 12-16-05, 10:29
ivon ivon is offline
Registered User
 
Join Date: Nov 2002
Posts: 272
No, I can't, I'm sorry.
I see you use the same code for two other fields. Do they work with empty strings?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On