Solved

sql to populate a field with None when is null

Posted on 2010-11-16
8
393 Views
Last Modified: 2012-08-14

All

Have a query that returns data including dates from a main table....however, where there is no date nothing returns and subsequent queries do not report this information as the [SoE review date] field is blank

in the below, where the field is Null - how do I get this to return 'none'

WHERE (((Z_ActiveEmployee_tblStatementDetails.[SoE review date])<Now() Or (Z_ActiveEmployee_tblStatementDetails.[SoE review date]) Is Null))

Full query SQL

SELECT Z_ActiveEmployee_tblStatementDetails.[Department Description], Z_SoEEligible.[Employee ID], Z_ActiveEmployee_tblStatementDetails.Surname, Z_ActiveEmployee_tblStatementDetails.[Given Name], Z_ActiveEmployee_tblStatementDetails.[Supervisor Name], Z_ActiveEmployee_tblStatementDetails.[SoE review date]
FROM Z_SoEEligible INNER JOIN Z_ActiveEmployee_tblStatementDetails ON Z_SoEEligible.[Employee ID] = Z_ActiveEmployee_tblStatementDetails.[Employee ID]
WHERE (((Z_ActiveEmployee_tblStatementDetails.[SoE review date])<Now() Or (Z_ActiveEmployee_tblStatementDetails.[SoE review date]) Is Null))
ORDER BY Z_ActiveEmployee_tblStatementDetails.[Department Description], Z_ActiveEmployee_tblStatementDetails.[Given Name], Z_ActiveEmployee_tblStatementDetails.[Supervisor Name];

TIA

Shaz

0
Comment
Question by:shaz0503
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 75
ID: 34150372
You can use the Nz() function

Nz([SoE review date], "None")

mx
0
 
LVL 5

Expert Comment

by:Zopilote
ID: 34150393
maybe
Or (Z_ActiveEmployee_tblStatementDetails.[SoE review date]) Is Null

is not null, but blank, try to remove all blanks first.
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34150416
Just be careful that using nz(.. , "none") will change the column type to TEXT.
It no longer contains dates, instead it contains TEXT of which some are a specific Format of the date/time.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75
ID: 34150447
shaz0503:

I assume by "return 'none'"  that you actually meant the word  None   ?

mx
0
 

Author Comment

by:shaz0503
ID: 34150507
Thanks all

DatabseMX suggestion works fine... I now need to see how this fits in the bigger scheme of things... one first play I don't know if this will work down the track - will get back later in the day...

rgds
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 500 total points
ID: 34150583
10-4
0
 

Author Comment

by:shaz0503
ID: 34235016
All

DatabaseMX above suggestion works fine and displays None in the relevant field.

My problem now is that I can't get a query to report 'none' in a subsequent query - just leaves that data out.

I have changed the field to text so date V text shouldn't be the issue..

any ideas (code attached)

rgds

S

CODE TO REPORT 'NONE' IN BLANK CELLS

SELECT Z_ActiveEmployee_tblStatementDetails.[Department Description], Z_SoEEligible.[Employee ID], Z_ActiveEmployee_tblStatementDetails.Surname, Z_ActiveEmployee_tblStatementDetails.[Given Name], Z_ActiveEmployee_tblStatementDetails.[Supervisor Name], Nz([SoE review date],"None") AS ReviewDate
FROM Z_SoEEligible INNER JOIN Z_ActiveEmployee_tblStatementDetails ON Z_SoEEligible.[Employee ID] = Z_ActiveEmployee_tblStatementDetails.[Employee ID]
WHERE (((Nz([SoE review date],"None"))<Now() Or (Nz([SoE review date],"None"))="none"))
ORDER BY Z_ActiveEmployee_tblStatementDetails.[Department Description], Z_ActiveEmployee_tblStatementDetails.[Given Name], Z_ActiveEmployee_tblStatementDetails.[Supervisor Name];


SUBSEQUENT CODE THAT DOES NOT REPORT THE 'NONE'

SELECT DeptByArea.School, DeptByArea.[Department Description], Z_SoEEligible.[Employee ID], Z_SoEEligible.Surname, Z_SoEEligible.[Given Name], Z_SoEEligible.[Supervisor Name], [Z_SoE Past Due].[SoE review date] AS [SoE Past Due], [Z_SoE Due within 60 days].[SoE Due Now] AS [SoE Now Due], ADSRIComments.Comments, Z_SoEEligible.[Eligibility Group]
FROM (((DeptByArea INNER JOIN Z_SoEEligible ON DeptByArea.[Department Description] = Z_SoEEligible.[Department Description]) LEFT JOIN [Z_SoE Due within 60 days] ON Z_SoEEligible.[Employee ID] = [Z_SoE Due within 60 days].[Employee ID]) LEFT JOIN [Z_SoE Past Due] ON Z_SoEEligible.[Employee ID] = [Z_SoE Past Due].[Employee ID]) LEFT JOIN ADSRIComments ON Z_SoEEligible.[Employee ID] = ADSRIComments.[Employee ID]
WHERE (((DeptByArea.School)="adsri") AND (([Z_SoE Past Due].[SoE review date]) Is Not Null)) OR (((DeptByArea.School)="adsri") AND (([Z_SoE Due within 60 days].[SoE Due Now]) Is Not Null));

Open in new window

0
 

Author Closing Comment

by:shaz0503
ID: 34884101
Thx DatabaseMX - working fine
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question