sqlserver 2000/2005 Ambiguous column error错误解决办法
2006-08-22 13:43
627 查看
今天针对Sql server 2005的脚本在Sql server 2000上执行,发生了两个错误
Msg 209, Level 16, State 1, Procedure tbh_Forums_GetUnapprovedPosts, Line 13
Ambiguous column name 'AddedDate'.
Msg 209, Level 16, State 1, Procedure tbh_Forums_GetThreadByID, Line 13
Ambiguous column name 'AddedDate'.
原来就是Forums表中和Post表中具有相同的列AddedDate,通过as 方式改写就可以解决了
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tbh_Forums_GetThreadByID]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[tbh_Forums_GetThreadByID]
(
@ThreadPostID int
)
AS
SET NOCOUNT ON
SELECT tbh_Posts.PostID, tbh_Posts.AddedDate as AddedDate, tbh_Posts.AddedBy, tbh_Posts.AddedByIP, tbh_Posts.ForumID, tbh_Posts.ParentPostID, tbh_Posts.Title, tbh_Posts.Body, tbh_Posts.Approved, tbh_Posts.Closed, tbh_Posts.ViewCount, tbh_Posts.ReplyCount, tbh_Posts.LastPostDate, tbh_Posts.LastPostBy,
tbh_Forums.Title AS ForumTitle
FROM tbh_Posts INNER JOIN
tbh_Forums ON tbh_Posts.ForumID = tbh_Forums.ForumID
WHERE PostID = @ThreadPostID OR ParentPostID = @ThreadPostID
ORDER BY AddedDate ASC'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tbh_Forums_GetUnapprovedPosts]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[tbh_Forums_GetUnapprovedPosts]
AS
SET NOCOUNT ON
SELECT tbh_Posts.PostID, tbh_Posts.AddedDate as AddedDate, tbh_Posts.AddedBy, tbh_Posts.AddedByIP, tbh_Posts.ForumID, tbh_Posts.ParentPostID, tbh_Posts.Title, tbh_Posts.Approved, tbh_Posts.Closed, tbh_Posts.ViewCount, tbh_Posts.ReplyCount, tbh_Posts.LastPostDate, tbh_Posts.LastPostBy,
tbh_Forums.Title AS ForumTitle, CASE
WHEN ParentPostID = 0 THEN 1
ELSE 0
END AS IsThreadPost
FROM tbh_Posts INNER JOIN
tbh_Forums ON tbh_Posts.ForumID = tbh_Forums.ForumID
WHERE Approved = 0
ORDER BY IsThreadPost DESC, AddedDate ASC'
END
GO
虽然这样解决了问题,这不应该是问题的真正原因,各位同学谁知道这个问题的真正原因?
自由、创新、研究、探索……
Msg 209, Level 16, State 1, Procedure tbh_Forums_GetUnapprovedPosts, Line 13
Ambiguous column name 'AddedDate'.
Msg 209, Level 16, State 1, Procedure tbh_Forums_GetThreadByID, Line 13
Ambiguous column name 'AddedDate'.
原来就是Forums表中和Post表中具有相同的列AddedDate,通过as 方式改写就可以解决了
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tbh_Forums_GetThreadByID]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[tbh_Forums_GetThreadByID]
(
@ThreadPostID int
)
AS
SET NOCOUNT ON
SELECT tbh_Posts.PostID, tbh_Posts.AddedDate as AddedDate, tbh_Posts.AddedBy, tbh_Posts.AddedByIP, tbh_Posts.ForumID, tbh_Posts.ParentPostID, tbh_Posts.Title, tbh_Posts.Body, tbh_Posts.Approved, tbh_Posts.Closed, tbh_Posts.ViewCount, tbh_Posts.ReplyCount, tbh_Posts.LastPostDate, tbh_Posts.LastPostBy,
tbh_Forums.Title AS ForumTitle
FROM tbh_Posts INNER JOIN
tbh_Forums ON tbh_Posts.ForumID = tbh_Forums.ForumID
WHERE PostID = @ThreadPostID OR ParentPostID = @ThreadPostID
ORDER BY AddedDate ASC'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tbh_Forums_GetUnapprovedPosts]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[tbh_Forums_GetUnapprovedPosts]
AS
SET NOCOUNT ON
SELECT tbh_Posts.PostID, tbh_Posts.AddedDate as AddedDate, tbh_Posts.AddedBy, tbh_Posts.AddedByIP, tbh_Posts.ForumID, tbh_Posts.ParentPostID, tbh_Posts.Title, tbh_Posts.Approved, tbh_Posts.Closed, tbh_Posts.ViewCount, tbh_Posts.ReplyCount, tbh_Posts.LastPostDate, tbh_Posts.LastPostBy,
tbh_Forums.Title AS ForumTitle, CASE
WHEN ParentPostID = 0 THEN 1
ELSE 0
END AS IsThreadPost
FROM tbh_Posts INNER JOIN
tbh_Forums ON tbh_Posts.ForumID = tbh_Forums.ForumID
WHERE Approved = 0
ORDER BY IsThreadPost DESC, AddedDate ASC'
END
GO
虽然这样解决了问题,这不应该是问题的真正原因,各位同学谁知道这个问题的真正原因?
自由、创新、研究、探索……
相关文章推荐
- sqlserver 2000/2005 Ambiguous column error错误解决办法
- sqlserver 2000/2005 Ambiguous column error错误解决办法
- 用sql server2005的错误 java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket. 解决办法
- SQLSERVER 2000 错误823解决办法
- 解决出现[SQLServer 2000 Driver for JDBC]Error establishing socket.的错误
- java操作数据库出现(][SQLServer 2000 Driver for JDBC]Error establishing socket.)的问题所在即解决办法
- “error LNK2005:…… already defined in”错误解决办法
- 解决出现[SQLServer 2000 Driver for JDBC]Error establishing socket.的错误
- sql server 2005 附加2000数据库文件时错误及解决办法
- MFC 出现error LNK2005错误的一种原因和解决办法
- SQL Server 2000 "Error establishing socket" 错误的解决办法
- [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket错误解决方法总结
- sql server 2005 附加2000数据库文件时错误及解决办法
- Sqlserver 2005附加数据库时出错提示操作系统错误5(拒绝访问)错误5120的解决办法
- 连接SQLServer时提示“但是在登录前的握手期间发生错误。 (provider: SSL Provider, error: 0 - 等待的操作过时”解决办法
- [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket错误解决方法总结
- Thinkphp 出现 “_CACHE_WRITE_ERROR” 错误的可能解决办法
- SAP BPC Automation error 及File not found错误解决办法
- Mysql修改密码,远程登录,ERROR 1044 (42000)错误解决办法
- window下工具访问linux下mysql出现 error no 2003 10061错误的解决办法