分配值为空的字段

问题描述 投票:0回答:1

我需要创建如下所示的字段,但是Policy Number字段为空,并且给我一个错误,因为查询不包括特定表达式作为聚合函数的一部分。

IIf((Format([Policy Create Date],"mm/dd/yyyy"))<"11/1/2019",[Customer ID],[Policy Number])


SELECT 
[Customer ID], 
IIf(IsNull([Policy Number]),'',Trim(Replace(UCase([Policy Number]),Chr(160)," "))) AS [Policy#], Min([Policy Create Date]) AS [Policy Create Date],
[Policy Carrier Plan], 
IIf((Format([Policy Create Date],"mm/dd/yyyy"))<"11/1/2019",[Customer ID],[Policy Number]) AS [AUX-FIELD]

FROM  [Agent Cubed (Same Plan)]

GROUP BY 
[Customer ID], 
IIf(IsNull([Policy Number]),'',Trim(Replace(UCase([Policy Number]),Chr(160)," "))), 
[Policy Carrier Plan], IIf((Format([Policy Create Date],"mm/dd/yyyy"))<"11/1/2019",
[Customer ID],
[Policy Number])
sql ms-access access-vba ms-access-2010 access
1个回答
0
投票

未聚合的那些columns应该成为您的group by子句的一部分。

SELECT [Customer ID]
    , IIf(IsNull([Policy Number]),'',Trim(Replace(UCase([Policy Number]),Chr(160)," "))) AS [Policy#]
    , Min([Policy Create Date]) AS [Policy Create Date]
    , [Policy Carrier Plan]
    , [Agent of Record 1 User Name]
    , [Agent Cubed Users].[User Key 02]
    , IIf((Format([Policy Create Date],"mm/dd/yyyy"))<"11/1/2019", [Customer ID], [Policy Number]) AS [AUX-FIELD]
    , DatePart("yyyy",[Policy Create Date]) & DatePart("q",[Policy Create Date]) AS YearQ
FROM  [Agent Cubed (Same Plan)]
GROUP BY [Customer ID]
    , IIf(IsNull([Policy Number]),'',Trim(Replace(UCase([Policy Number]),Chr(160)," ")))    
    , [Policy Carrier Plan]
    , [Agent of Record 1 User Name]
    , [Agent Cubed Users].[User Key 02]
    , IIf((Format([Policy Create Date],"mm/dd/yyyy"))<"11/1/2019", [Customer ID], [Policy Number]) 
    , DatePart("yyyy",[Policy Create Date]) & DatePart("q",[Policy Create Date]) 
HAVING (((DatePart("yyyy",[Policy Create Date]) & DatePart("q",[Policy Create Date]))=4))
© www.soinside.com 2019 - 2024. All rights reserved.