Subquery using ANYELEMENT with Entity SQL

168 Views Asked by At

According to the Microsoft Documents (http://msdn.microsoft.com/en-us/library/bb738573.aspx) for Entity SQL in order to return a scalar subquery I need to use the function ANYELEMENT().

However, when I try that I am getting this as my returned values:

System.Data.Query.ResultAssembly.BridgeDataRecord

My query:

SELECT

ANYELEMENT(
SELECT SUM(CASE WHEN B.EXECUTION_STATUS_ID=2 THEN 1 ELSE 0 END)
    FROM SpiraTestEntities.R_TestCases AS B
    WHERE TruncateTime(B.EXECUTION_DATE) <= DateExecuted) AS PASSED,

DateExecuted


FROM SpiraTestEntities.R_TestCases as A

where A.PROJECT_ID = ${ProjectId}

AND A.IS_DELETED = false

AND A.EXECUTION_DATE IS NOT NULL

GROUP BY 

TruncateTime(A.EXECUTION_DATE) as DateExecuted

I should be getting something more like this:

PASSED      DateExecuted
------      ------------
   37       2014-06-05
   67       2014-06-06
   92       2014-06-09

But I'm getting this:

PASSED                                                      DateExecuted
------                                                      ------------
System.Data.Query.ResultAssembly.BridgeDataRecord            2014-06-05
System.Data.Query.ResultAssembly.BridgeDataRecord            2014-06-06
System.Data.Query.ResultAssembly.BridgeDataRecord            2014-06-09

Any ideas?

1

There are 1 best solutions below

0
On

Add VALUE after the SELECT:

ANYELEMENT(SELECT VALUE SUM(CASE WHEN ...