创建索引视图
当我尝试创建索引视图时,出现错误“datepart 返回不确定性值,使用系统定义的确定性函数或使用户定义的函数返回确定性值” 当我尝试在视图上创建索引时,出现此错误
。查询是
CREATE VIEW dbo.two_weeks_performance WITH SCHEMABINDING
as
SELECT dbo.day_dim.date_time AS Date, dbo.order_dim.quantity AS Target_Acheived
FROM dbo.day_dim
JOIN dbo.order_fact ON dbo.day_dim.day_id = dbo.order_fact.day_id
JOIN dbo.branch_dim ON dbo.order_fact.branch_id = dbo.branch_dim.branch_id
JOIN dbo.order_dim ON dbo.order_fact.order_id = dbo.order_dim.order_id
WHERE (DATEPART(wk, CONVERT(datetime, dbo.day_dim.date_time, 101)) <= DATEPART(wk, GETDATE() - 2))
GROUP BY dbo.order_dim.quantity, dbo.day_dim.date_time
GO
CREATE UNIQUE CLUSTERED INDEX two_weeks_performance_I on two_weeks_performance (Date,Target_Acheived)`
在这个date_time是varchar(30)类型。给我一个解决方案来解决这个问题。
When I try to create indexed view I am getting an error "datepart returns indeterministic value, use system defined deterministic function or make the user defined function to return deterministic value" I get this error when i try to create index on the view..
The query is
CREATE VIEW dbo.two_weeks_performance WITH SCHEMABINDING
as
SELECT dbo.day_dim.date_time AS Date, dbo.order_dim.quantity AS Target_Acheived
FROM dbo.day_dim
JOIN dbo.order_fact ON dbo.day_dim.day_id = dbo.order_fact.day_id
JOIN dbo.branch_dim ON dbo.order_fact.branch_id = dbo.branch_dim.branch_id
JOIN dbo.order_dim ON dbo.order_fact.order_id = dbo.order_dim.order_id
WHERE (DATEPART(wk, CONVERT(datetime, dbo.day_dim.date_time, 101)) <= DATEPART(wk, GETDATE() - 2))
GROUP BY dbo.order_dim.quantity, dbo.day_dim.date_time
GO
CREATE UNIQUE CLUSTERED INDEX two_weeks_performance_I on two_weeks_performance (Date,Target_Acheived)`
In this date_time is varchar(30) type. Give me a solution to over come this problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用:
问题是 GETDATE() 的使用;它是不确定的,每次都会返回不同的值。
所以你必须使用:
Use:
The issue was the use of GETDATE(); it's non-deterministic, returning a different value every time.
So you'd have to use: