我正在使用Crystal Reports,它使您可以创建称为SQL表达式的内容。它们基本上是子查询,但受到限制,因此每个SQL表达式只能返回标量值。有关更多信息,请访问:http://www.cogniza.com/wordpress/2005/11/07/crystal-reports-using-sql-expression-fields/
所引用的文章非常明确地指出:
If you are using a SQL Expression as a subquery and wish to link it to the
detail row of your main report, do not include the table you wish to link to
in the FROM clause of the subquery. For example:
(
SELECT MAX("FLOWSHEET"."VALUE")
FROM FLOWSHEET
WHERE "FLOWSHEET"."ID" in ('11')
AND "FLOWSHEET"."IP_ID" = "HOSPITAL_VISIT"."IP_ID"
)
The above query links to the HOSPITAL_VISIT table in the main report by
linking to the IP_ID field. To accomplish this, HOSPITAL_VISIT is omitted
from the FROM clause in the query.
我的报告中有一个主要查询,内容为:
SELECT
HIFIS_HousePlacements.MovedInDate,
vw_ClientBasics.LastName,
vw_ClientBasics.FirstName,
HIFIS_Clients_HousePlacements.ClientID
FROM
HIFIS_Clients_HousePlacements
INNER JOIN HIFIS_HousePlacements ON HIFIS_Clients_HousePlacements.HousePlacementID=HIFIS_HousePlacements.HousePlacementID
INNER JOIN vw_ClientBasics ON HIFIS_Clients_HousePlacements.ClientID=vw_ClientBasics.ClientID
现在我要添加一个SQL表达式
(
SELECT TOP 1 AssessmentAcuityType
FROM vw_IntakeAssessmentAcuityScores
WHERE vw_IntakeAssessmentAcuityScores.ClientID=HIFIS_Clients_HousePlacements.ClientID
AND vw_IntakeAssessmentAcuityScores.AssessmentTool = 'SPDAT'
AND vw_IntakeAssessmentAcuityScores.AssessmentToolType NOT LIKE '%VI%'
AND vw_IntakeAssessmentAcuityScores.IntakeDate BETWEEN DATEADD(month,-6,HIFIS_HousePlacements.MovedInDate) AND HIFIS_HousePlacements.MovedInDate
ORDER BY IntakeID DESC
)
这样做时,我收到错误The multi-part identifier HIFIS_HousePlacements.MovedInDate cannot be bound
因此,尽管我知道我没有在子查询中定义HIFIS_HousePlacements,但是SQL Expression字段的规则指出我不应该这样做。有人能帮助我了解如何解决此错误吗?
答案 0 :(得分:0)
我已经解决了部分问题。
部分问题取决于方程边的顺序。
所以我确定这会导致错误:
(
SELECT TOP 1 AssessmentAcuityType
FROM vw_IntakeAssessmentAcuityScores
WHERE vw_IntakeAssessmentAcuityScores.ClientID=HIFIS_Clients_HousePlacements.ClientID
)
这不是
(
SELECT TOP 1 AssessmentAcuityType
FROM vw_IntakeAssessmentAcuityScores
WHERE HIFIS_Clients_HousePlacements.ClientID=vw_IntakeAssessmentAcuityScores.ClientID
)