Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

sql to populate a field with None when is null

Posted on 2010-11-16
8
Medium Priority
?
409 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

Industry Leaders: 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!

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

886 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