首页 新闻 会员 周边 捐助

视图索引的问题

0
悬赏园豆:5 [已关闭问题] 关闭于 2015-11-27 12:46

use mlk;
GO
SET NUMERIC_ROUNDABORT OFF;
SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT,
    QUOTED_IDENTIFIER, ANSI_NULLS ON;
GO
IF OBJECT_ID ('dbo.mt1', 'view') IS NOT NULL
DROP VIEW dbo.mt1;
GO
CREATE VIEW dbo.mt1
WITH SCHEMABINDING AS
SELECT
COUNT_BIG(*) AS counts,

//大概错误是在这里
SUM(dbo.TT_MT_LOG.MT_NOREPORT+dbo.TT_MT_LOG.MT_SUCCESS) sums,


dbo.TT_MT_LOG.APP_PARAMETER1 AS BizCode,
CONVERT(datetime,CONVERT (CHAR(10),dbo.TT_MT_LOG.SEND_TIME,120),120) AS Days

FROM
dbo.TT_MT_LOG
GROUP BY
dbo.TT_MT_LOG.APP_PARAMETER1,
CONVERT(datetime,CONVERT (CHAR(10),dbo.TT_MT_LOG.SEND_TIME,120),120)

GO
CREATE UNIQUE CLUSTERED INDEX mt_1 ON mlk.dbo.mt1(days DESC,BizCode);
GO

错误信息:

[SQL]
CREATE UNIQUE CLUSTERED INDEX mt_1 ON mlk.dbo.mt1(days DESC,BizCode)
[Err] 42000 - [SQL Server]Cannot create the clustered index "mt_1" on view "mlk.dbo.mt1" because the view references an unknown value (SUM aggregate of nullable expression). Consider referencing only non-nullable values in SUM. ISNULL() may be useful for this.

求大神们指点。

狗霸人间的主页 狗霸人间 | 初学一级 | 园豆:4
提问于:2015-11-19 14:09
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册