我有一个按周分组结果的查询。 为了确保一周开始一致,我试图将第一行添加到Peta Poco db.Query(sql)方法中。
SET DATEFIRST 1
SELECT
count(logDate) as Value,
dateadd(WEEK, datediff(WEEK,0, logDate),0) as [Date]
FROM
... etc ...
如果没有SET DATEFIRST 1
PetaPoco会产生类似......
exec sp_executesql N'
SELECT
count(logDate) as Value,
dateadd(WEEK, datediff(WEEK,0, logDate),0) as [Date]
FROM
... etc ...
使用SET DATEFIRST 1
PetaPoco生成类似......
exec sp_executesql N'SELECT [DataPoint].[Date], [DataPoint].[Value] FROM [DataPoint]
SET DATEFIRST 1
SELECT
count(logDate) as Value,
dateadd(WEEK, datediff(WEEK,0, logDate),0) as [Date]
FROM
... etc ...
如何解决此问题导致错误的SQL?
从文档中看,我可以使用db.Execute("SET DATEFIRST 1");
,只要它在同一个连接上执行,但由于连接都是为我管理的,我是否需要做任何事情以确保它是相同的连接作为我的查询?
答案 0 :(得分:2)
将分号作为第一个char,告诉PetaPoco按原样执行查询
db.Execute(";SET DATEFIRST 1 ....