我正在使用WebMatrix运行我的查询,我认为这是正确的,但是我收到了错误。
我的查询如下:
var result = db.Query(
@"SELECT e.event_id, e.title, e.description, e.event_start, e.event_end, e.group_id, e.recurring
FROM event e
JOIN Membership m ON m.GroupID = e.group_id
WHERE e.recurring = 0
AND m.UserID = @0
AND e.event_start >= @1
AND e.event_end <= @2
UNION ALL
SELECT e.event_id, e.title, e.description, DATEADD(week, w.weeks, e.event_start), DATEADD(week, w.weeks, e.event_end), e.group_id, e.recurring
FROM event e
JOIN Membership m ON m.GroupID = e.group_id
CROSS JOIN
( SELECT row_number() OVER (ORDER BY Object_ID) AS weeks
FROM SYS.OBJECTS
) AS w
WHERE e.recurring = 1
AND m.user_id = 4;
AND e.event_start >= @4
AND e.event_end <= @5", userID, start, end, userID, start, end
);
错误是:
System.Data.SqlServerCe.SqlCeException(0x80004005):有一个 解析查询时出错。 [令牌行号= 10,令牌行偏移= 38,令牌错误= OVER] at System.Data.SqlServerCe.SqlCeCommand.ProcessResults(Int32 hr)at System.Data.SqlServerCe.SqlCeCommand.CompileQueryPlan()
我在.cs文件中持有查询。我被告知我应该创建一个存储过程,因为SQL Server compact可能不支持OVER功能,这是正确的吗?如何为此查询创建存储过程?
答案 0 :(得分:1)
在FROM之后,您可以列出以逗号分隔的多个表格,结果将是所有这些表格的CROSS JOIN。
但是你不能在JOIN之后使用逗号语法。相反,写出CROSS JOIN:
JOIN Membership m
ON m.GroupID = e.group_id
CROSS JOIN
(
SELECT row_number() OVER (ORDER BY Object_ID) AS weeks
FROM SYS.OBJECTS
) AS w
答案 1 :(得分:0)
似乎SOW Server CE 4.0不支持ROW_NUMBER和其他窗口函数:(