The problem is that the physical table is generated by the code, and the table name varies on the running condition. I shouldn't be able to add it to my LLBLGen project, right?
I wanted to generate the following query to "SELECT" everything but only "GROUP BY" on VISITOR_ID column so the HAVING condition is calculated on VISITOR_ID level. I guess I need a subquery or a temporal physical table (the IN clause):
SELECT [SESSION].[VISITOR_ID] AS [VISITOR_ID],
[SESSION].[ID] AS [SESSION_ID],
** Count([EVENT_OCCURRENCE].ID) OVER(PARTITION BY [SESSION].[VISITOR_ID]) AS [MATCHES] **
FROM ( [SESSION] INNER JOIN [EVENT_OCCURRENCE]
ON [SESSION].[ID]=[EVENT_OCCURRENCE].[SESSION_ID])
WHERE ( ( [EVENT_OCCURRENCE].[EVENT_ID] = 50)
AND ( [SESSION].[END] >= '11/01/2010 12:00:00 AM'
AND [SESSION].[END] <= '11/01/2010 11:59:59 PM')
AND ( [SESSION].[VISITOR_ID] <> 0)
AND [SESSION].[VISITOR_ID] IN (**SELECT [SESSION].[VISITOR_ID] AS [VISITOR_ID]
FROM ( [SESSION] INNER JOIN [EVENT_OCCURRENCE]
ON [SESSION].[ID]=[EVENT_OCCURRENCE].[SESSION_ID])
WHERE ( ( [EVENT_OCCURRENCE].[EVENT_ID] = 50)
AND ( [SESSION].[END] >= '11/01/2010 12:00:00 AM'
AND [SESSION].[END] <= '11/01/2010 11:59:59 PM')
AND ( [SESSION].[VISITOR_ID] <> 0))
GROUP BY [SESSION].[VISITOR_ID]
HAVING ( COUNT([EVENT_OCCURRENCE].[ID]) >= 2))**)
This is for SQL Server 2008 R2. SESSION and EVENT_OCCURENCE are both in the LLBLGEN project.
I intend to make the subquery result into a temporal table, then either use the IN clause or JOIN.
Could derived table be used if I use JOIN instead of IN?
daelmo wrote:
jia wrote:
Sorry I didn't make myself clear. It's a physical table created for a temporary purpose.
If it's a physical table created by you, then you can add it to your LLBLGen project so you would be able to use it when constructing LLBLGen queries. Am I right?
If you don't do that, I don't see other option than use your own stored procedure. Then you can project the stored procedure result into an entity collection.