Solved

sql to populate a field with None when is null

Posted on 2010-11-16
8
350 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

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
You can use the Nz() function

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

mx
0
 
LVL 5

Expert Comment

by:Zopilote
Comment Utility
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
Comment Utility
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
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
shaz0503:

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

mx
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:shaz0503
Comment Utility
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
Comment Utility
10-4
0
 

Author Comment

by:shaz0503
Comment Utility
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
Comment Utility
Thx DatabaseMX - working fine
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now