Solved

sql to populate a field with None when is null

Posted on 2010-11-16
8
380 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

808 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