末尾有图为证。。
/****** Object: View [dbo].[ViewBill] Script Date: 04/05/2014 13:43:40 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[ViewBill]
AS
SELECT TOP (100) PERCENT a.CustomerName, a.BId, a.ClientId, a.BNumber, a.BOperId, a.Receiver, a.ReceiveTime, a.Total, b.MovNO1, b.MovNO2, b.MovNO3,
b.MovNO4, b.Tel1, b.IDNumber, b.Tel2, b.Sex, c.DictonaryDesc AS sexName, TblManagement_2.SystemName AS BOperName,
TblManagement_1.SystemName AS ReceiverName, ISNULL(a.CustomerName, '') + ISNULL(b.IDNumber, '') + ISNULL(b.MovNO1, '')
+ ISNULL(b.MovNO2, '') + ISNULL(b.MovNO3, '') + ISNULL(b.MovNO4, '') + ISNULL(b.Tel1, '') + ISNULL(b.PHCode, '') + ISNULL(b.Tel2, '')
+ ISNULL(b.Address, '') + ISNULL(a.BNumber, '') AS keyWords, b.Address, b.PHCode
FROM dbo.TblManagement AS TblManagement_1 RIGHT OUTER JOIN
dbo.TblBill AS a ON TblManagement_1.Mid = a.Receiver LEFT OUTER JOIN
dbo.TblManagement AS TblManagement_2 ON a.BOperId = TblManagement_2.Mid LEFT OUTER JOIN
dbo.TblCommonDictionary AS c RIGHT OUTER JOIN
dbo.TblCustomers AS b ON c.Id = b.Sex ON a.ClientId = b.ClientId
ORDER BY a.BId DESC
GO
EXEC dbo.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties =
Begin PaneConfigurations =
Begin PaneConfiguration = 0
NumPanes = 4
Configuration = "(H (1[41] 4[14] 2[27] 3) )"
End
Begin PaneConfiguration = 1
NumPanes = 3
Configuration = "(H (1 [50] 4 [25] 3))"
End
Begin PaneConfiguration = 2
NumPanes = 3
Configuration = "(H (1 [50] 2 [25] 3))"
End
Begin PaneConfiguration = 3
NumPanes = 3
Configuration = "(H (4 [30] 2 [40] 3))"
End
Begin PaneConfiguration = 4
NumPanes = 2
Configuration = "(H (1 [56] 3))"
End
Begin PaneConfiguration = 5
NumPanes = 2
Configuration = "(H (2 [66] 3))"
End
Begin PaneConfiguration = 6
NumPanes = 2
Configuration = "(H (4 [50] 3))"
End
Begin PaneConfiguration = 7
NumPanes = 1
Configuration = "(V (3))"
End
Begin PaneConfiguration = 8
NumPanes = 3
Configuration = "(H (1[56] 4[18] 2) )"
End
Begin PaneConfiguration = 9
NumPanes = 2
Configuration = "(H (1 [75] 4))"
End
Begin PaneConfiguration = 10
NumPanes = 2
Configuration = "(H (1[66] 2) )"
End
Begin PaneConfiguration = 11
NumPanes = 2
Configuration = "(H (4 [60] 2))"
End
Begin PaneConfiguration = 12
NumPanes = 1
Configuration = "(H (1) )"
End
Begin PaneConfiguration = 13
NumPanes = 1
Configuration = "(V (4))"
End
Begin PaneConfiguration = 14
NumPanes = 1
Configuration = "(V (2))"
End
ActivePaneConfig = 0
End
Begin DiagramPane =
Begin Origin =
Top = 0
Left = 0
End
Begin Tables =
Begin Table = "TblManagement_1"
Begin Extent =
Top = 6
Left = 38
Bottom = 121
Right = 191
End
DisplayFlags = 280
TopColumn = 0
End
Begin Table = "a"
Begin Extent =
Top = 4
Left = 287
Bottom = 222
Right = 441
End
DisplayFlags = 280
TopColumn = 0
End
Begin Table = "TblManagement_2"
Begin Extent =
Top = 126
Left = 38
Bottom = 241
Right = 191
End
DisplayFlags = 280
TopColumn = 0
End
Begin Table = "c"
Begin Extent =
Top = 88
Left = 510
Bottom = 279
Right = 670
End
DisplayFlags = 280
TopColumn = 0
End
Begin Table = "b"
Begin Extent =
Top = 26
Left = 105
Bottom = 263
Right = 259
End
DisplayFlags = 280
TopColumn = 0
End
End
End
Begin SQLPane =
End
Begin DataPane =
Begin ParameterDefaults = ""
End
Begin ColumnWidths = 23
Width = 284
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1' , @level0type=N'USER',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'ViewBill'
GO
EXEC dbo.sp_addextendedproperty @name=N'MS_DiagramPane2', @value=N'500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 2130
Width = 1500
Width = 1500
End
End
Begin CriteriaPane =
Begin ColumnWidths = 11
Column = 1440
Alias = 900
Table = 1170
Output = 720
Append = 1400
NewValue = 1170
SortType = 1350
SortOrder = 1410
GroupBy = 1350
Filter = 1350
Or = 1350
Or = 1350
Or = 1350
End
End
End
' , @level0type=N'USER',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'ViewBill'
GO
EXEC dbo.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=2 , @level0type=N'USER',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'ViewBill'
GO
这张图片上就是出错的地方 和 错误提示信息 求大神啊!!
8 个解决方案
#1
经过我的反复测试 证明下面这段话有问题 但又不知道问题在哪里?
下面是代码
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[ViewBill]
AS
SELECT TOP (100) PERCENT a.CustomerName, a.BId, a.ClientId, a.BNumber, a.BOperId, a.Receiver, a.ReceiveTime, a.Total, b.MovNO1, b.MovNO2, b.MovNO3,
b.MovNO4, b.Tel1, b.IDNumber, b.Tel2, b.Sex, c.DictonaryDesc AS sexName, TblManagement_2.SystemName AS BOperName,
TblManagement_1.SystemName AS ReceiverName, ISNULL(a.CustomerName, '') + ISNULL(b.IDNumber, '') + ISNULL(b.MovNO1, '')
+ ISNULL(b.MovNO2, '') + ISNULL(b.MovNO3, '') + ISNULL(b.MovNO4, '') + ISNULL(b.Tel1, '') + ISNULL(b.PHCode, '') + ISNULL(b.Tel2, '')
+ ISNULL(b.Address, '') + ISNULL(a.BNumber, '') AS keyWords, b.Address, b.PHCode
FROM dbo.TblManagement AS TblManagement_1 RIGHT OUTER JOIN
dbo.TblBill AS a ON TblManagement_1.Mid = a.Receiver LEFT OUTER JOIN
dbo.TblManagement AS TblManagement_2 ON a.BOperId = TblManagement_2.Mid LEFT OUTER JOIN
dbo.TblCommonDictionary AS c RIGHT OUTER JOIN
dbo.TblCustomers AS b ON c.Id = b.Sex ON a.ClientId = b.ClientId
ORDER BY a.BId DESC
GO
下面是代码
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[ViewBill]
AS
SELECT TOP (100) PERCENT a.CustomerName, a.BId, a.ClientId, a.BNumber, a.BOperId, a.Receiver, a.ReceiveTime, a.Total, b.MovNO1, b.MovNO2, b.MovNO3,
b.MovNO4, b.Tel1, b.IDNumber, b.Tel2, b.Sex, c.DictonaryDesc AS sexName, TblManagement_2.SystemName AS BOperName,
TblManagement_1.SystemName AS ReceiverName, ISNULL(a.CustomerName, '') + ISNULL(b.IDNumber, '') + ISNULL(b.MovNO1, '')
+ ISNULL(b.MovNO2, '') + ISNULL(b.MovNO3, '') + ISNULL(b.MovNO4, '') + ISNULL(b.Tel1, '') + ISNULL(b.PHCode, '') + ISNULL(b.Tel2, '')
+ ISNULL(b.Address, '') + ISNULL(a.BNumber, '') AS keyWords, b.Address, b.PHCode
FROM dbo.TblManagement AS TblManagement_1 RIGHT OUTER JOIN
dbo.TblBill AS a ON TblManagement_1.Mid = a.Receiver LEFT OUTER JOIN
dbo.TblManagement AS TblManagement_2 ON a.BOperId = TblManagement_2.Mid LEFT OUTER JOIN
dbo.TblCommonDictionary AS c RIGHT OUTER JOIN
dbo.TblCustomers AS b ON c.Id = b.Sex ON a.ClientId = b.ClientId
ORDER BY a.BId DESC
GO
#2
重来一张 这问题的出现在于 它是sql08生成的脚本,而在sql2000上执行错误。。。
重写发图
重写发图
#3
是不是这个 TOP (100) PERCENT 有问题呢
#4
去掉 TOP (100) PERCENT 试试
#5
有没有可能是不同的数据库中的表呢? 你的这个表都没有写库名呢
#6
视图中不允许使用top和order by,除非是在子查询中
#7
记错了,是不允许直接order by,指定了top是可以的。
我试了一下,问题在top (100) ,2008是没问题的,2000中这个括号是多余的,要去掉,否则报错
#8
导出脚本时选兼容级别为sql server 2000就行了
#1
经过我的反复测试 证明下面这段话有问题 但又不知道问题在哪里?
下面是代码
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[ViewBill]
AS
SELECT TOP (100) PERCENT a.CustomerName, a.BId, a.ClientId, a.BNumber, a.BOperId, a.Receiver, a.ReceiveTime, a.Total, b.MovNO1, b.MovNO2, b.MovNO3,
b.MovNO4, b.Tel1, b.IDNumber, b.Tel2, b.Sex, c.DictonaryDesc AS sexName, TblManagement_2.SystemName AS BOperName,
TblManagement_1.SystemName AS ReceiverName, ISNULL(a.CustomerName, '') + ISNULL(b.IDNumber, '') + ISNULL(b.MovNO1, '')
+ ISNULL(b.MovNO2, '') + ISNULL(b.MovNO3, '') + ISNULL(b.MovNO4, '') + ISNULL(b.Tel1, '') + ISNULL(b.PHCode, '') + ISNULL(b.Tel2, '')
+ ISNULL(b.Address, '') + ISNULL(a.BNumber, '') AS keyWords, b.Address, b.PHCode
FROM dbo.TblManagement AS TblManagement_1 RIGHT OUTER JOIN
dbo.TblBill AS a ON TblManagement_1.Mid = a.Receiver LEFT OUTER JOIN
dbo.TblManagement AS TblManagement_2 ON a.BOperId = TblManagement_2.Mid LEFT OUTER JOIN
dbo.TblCommonDictionary AS c RIGHT OUTER JOIN
dbo.TblCustomers AS b ON c.Id = b.Sex ON a.ClientId = b.ClientId
ORDER BY a.BId DESC
GO
下面是代码
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[ViewBill]
AS
SELECT TOP (100) PERCENT a.CustomerName, a.BId, a.ClientId, a.BNumber, a.BOperId, a.Receiver, a.ReceiveTime, a.Total, b.MovNO1, b.MovNO2, b.MovNO3,
b.MovNO4, b.Tel1, b.IDNumber, b.Tel2, b.Sex, c.DictonaryDesc AS sexName, TblManagement_2.SystemName AS BOperName,
TblManagement_1.SystemName AS ReceiverName, ISNULL(a.CustomerName, '') + ISNULL(b.IDNumber, '') + ISNULL(b.MovNO1, '')
+ ISNULL(b.MovNO2, '') + ISNULL(b.MovNO3, '') + ISNULL(b.MovNO4, '') + ISNULL(b.Tel1, '') + ISNULL(b.PHCode, '') + ISNULL(b.Tel2, '')
+ ISNULL(b.Address, '') + ISNULL(a.BNumber, '') AS keyWords, b.Address, b.PHCode
FROM dbo.TblManagement AS TblManagement_1 RIGHT OUTER JOIN
dbo.TblBill AS a ON TblManagement_1.Mid = a.Receiver LEFT OUTER JOIN
dbo.TblManagement AS TblManagement_2 ON a.BOperId = TblManagement_2.Mid LEFT OUTER JOIN
dbo.TblCommonDictionary AS c RIGHT OUTER JOIN
dbo.TblCustomers AS b ON c.Id = b.Sex ON a.ClientId = b.ClientId
ORDER BY a.BId DESC
GO
#2
重来一张 这问题的出现在于 它是sql08生成的脚本,而在sql2000上执行错误。。。
重写发图
重写发图
#3
是不是这个 TOP (100) PERCENT 有问题呢
#4
去掉 TOP (100) PERCENT 试试
#5
有没有可能是不同的数据库中的表呢? 你的这个表都没有写库名呢
#6
视图中不允许使用top和order by,除非是在子查询中
#7
记错了,是不允许直接order by,指定了top是可以的。
我试了一下,问题在top (100) ,2008是没问题的,2000中这个括号是多余的,要去掉,否则报错
#8
导出脚本时选兼容级别为sql server 2000就行了