KAdamsbaum
New member
- Local time
- Today, 12:33
- Joined
- Jun 27, 2013
- Messages
- 5
Hi all,
Hoping someone can explain why I am getting an error with the Nz function in Access 2002. The code below is the same for each example, just showing the different samples (sorry for all the code). Each line is a subquery and the same, the only difference is the change of the date. There is more to the query (other fields) but that all works fine, only the part highlighted is the questionable part. In Example 1, you will see that the Nz function is on line 1 (subquery 1) but not on line 2 and this works (field for line 2 is returned null since Nz is not used). Note: all other lines work fine. In Example 2, this is switched, line one does not have Nz function (field for line 1 is returned null since Nz is not used), but line 2 does and this works. Note: all other lines work fine. In Example 3, both line 1 and 2 have function Nz and does not work, produces error: Data Type Mismatch in Criteria Expression. I have no idea as to why this is happening. Logically this should work, in reality, it is not working. WHY???? :banghead: Like I stated earlier, the only thing that changes from line to line is the date. The lines 3 – 12 have no bearing on the first 2. If I remove lines 3 – 12 and only worked with first 2, same situation occurs. It just makes no sense to me
Another quick question relating to same. The source field is formatted as number (right justified), but when the result is returned, it is a string (left justified). Is there a way to correct / fix this so it is a number in the result not a string? Why does Nz convert result to string if it starts as number and most times source is populate, so would expect to still come out as a number not a string.
Thanks in advance for any help you can give.
Kenny
Example 1
This works
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #1/1/2010#),0) AS [201001 TOTAL],
(Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #2/1/2010#) AS [201002 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #3/1/2010#),0) AS [201003 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #4/1/2010#),0) AS [201004 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #5/1/2010#),0) AS [201005 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #6/1/2010#),0) AS [201006 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #7/1/2010#),0) AS [201007 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #8/1/2010#),0) AS [201008 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #9/1/2010#),0) AS [201009 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #10/1/2010#),0) AS [201010 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #11/1/2010#),0) AS [201011 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #12/1/2010#),0) AS [201012 TOTAL],
Example 2
This works
(Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #1/1/2010#) AS [201001 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #2/1/2010#),0) AS [201002 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #3/1/2010#),0) AS [201003 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #4/1/2010#),0) AS [201004 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #5/1/2010#),0) AS [201005 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #6/1/2010#),0) AS [201006 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #7/1/2010#),0) AS [201007 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #8/1/2010#),0) AS [201008 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #9/1/2010#),0) AS [201009 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #10/1/2010#),0) AS [201010 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #11/1/2010#),0) AS [201011 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #12/1/2010#),0) AS [201012 TOTAL],
Example 3
This Does Not Work – Error is: Data Type Mismatch in Criteria Expression
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #1/1/2010#),0) AS [201001 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #2/1/2010#),0) AS [201002 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #3/1/2010#),0) AS [201003 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #4/1/2010#),0) AS [201004 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #5/1/2010#),0) AS [201005 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #6/1/2010#),0) AS [201006 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #7/1/2010#),0) AS [201007 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #8/1/2010#),0) AS [201008 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #9/1/2010#),0) AS [201009 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #10/1/2010#),0) AS [201010 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #11/1/2010#),0) AS [201011 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #12/1/2010#),0) AS [201012 TOTAL],
Hoping someone can explain why I am getting an error with the Nz function in Access 2002. The code below is the same for each example, just showing the different samples (sorry for all the code). Each line is a subquery and the same, the only difference is the change of the date. There is more to the query (other fields) but that all works fine, only the part highlighted is the questionable part. In Example 1, you will see that the Nz function is on line 1 (subquery 1) but not on line 2 and this works (field for line 2 is returned null since Nz is not used). Note: all other lines work fine. In Example 2, this is switched, line one does not have Nz function (field for line 1 is returned null since Nz is not used), but line 2 does and this works. Note: all other lines work fine. In Example 3, both line 1 and 2 have function Nz and does not work, produces error: Data Type Mismatch in Criteria Expression. I have no idea as to why this is happening. Logically this should work, in reality, it is not working. WHY???? :banghead: Like I stated earlier, the only thing that changes from line to line is the date. The lines 3 – 12 have no bearing on the first 2. If I remove lines 3 – 12 and only worked with first 2, same situation occurs. It just makes no sense to me
Another quick question relating to same. The source field is formatted as number (right justified), but when the result is returned, it is a string (left justified). Is there a way to correct / fix this so it is a number in the result not a string? Why does Nz convert result to string if it starts as number and most times source is populate, so would expect to still come out as a number not a string.
Thanks in advance for any help you can give.
Kenny
Example 1
This works
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #1/1/2010#),0) AS [201001 TOTAL],
(Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #2/1/2010#) AS [201002 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #3/1/2010#),0) AS [201003 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #4/1/2010#),0) AS [201004 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #5/1/2010#),0) AS [201005 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #6/1/2010#),0) AS [201006 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #7/1/2010#),0) AS [201007 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #8/1/2010#),0) AS [201008 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #9/1/2010#),0) AS [201009 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #10/1/2010#),0) AS [201010 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #11/1/2010#),0) AS [201011 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #12/1/2010#),0) AS [201012 TOTAL],
Example 2
This works
(Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #1/1/2010#) AS [201001 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #2/1/2010#),0) AS [201002 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #3/1/2010#),0) AS [201003 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #4/1/2010#),0) AS [201004 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #5/1/2010#),0) AS [201005 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #6/1/2010#),0) AS [201006 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #7/1/2010#),0) AS [201007 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #8/1/2010#),0) AS [201008 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #9/1/2010#),0) AS [201009 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #10/1/2010#),0) AS [201010 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #11/1/2010#),0) AS [201011 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #12/1/2010#),0) AS [201012 TOTAL],
Example 3
This Does Not Work – Error is: Data Type Mismatch in Criteria Expression
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #1/1/2010#),0) AS [201001 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #2/1/2010#),0) AS [201002 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #3/1/2010#),0) AS [201003 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #4/1/2010#),0) AS [201004 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #5/1/2010#),0) AS [201005 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #6/1/2010#),0) AS [201006 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #7/1/2010#),0) AS [201007 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #8/1/2010#),0) AS [201008 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #9/1/2010#),0) AS [201009 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #10/1/2010#),0) AS [201010 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #11/1/2010#),0) AS [201011 TOTAL],
Nz((Select Sum( [Client Amt].[Renewal Prem]) From [Client Amt] Where [ Amt].HICN = [Client Amt].[RET HICN] and [Client Amt].[Eff Date] = #12/1/2010#),0) AS [201012 TOTAL],