Solved

sql to populate a field with None when is null

Posted on 2010-11-16
8
374 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
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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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 - Access MVP) 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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…

823 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