博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
sqlserver 2000/2005 Ambiguous column error错误解决办法
阅读量:5897 次
发布时间:2019-06-19

本文共 2082 字,大约阅读时间需要 6 分钟。

今天针对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
虽然这样解决了问题,这不应该是问题的真正原因,各位同学谁知道这个问题的真正原因?
本文转自 张善友 51CTO博客,原文链接:http://blog.51cto.com/shanyou/75025,如需转载请自行联系原作者
你可能感兴趣的文章
Bootstrap清除浮动的实现原理
查看>>
初学vue2.0-组件-文档理解笔记v1.0
查看>>
NG-ZORRO-MOBILE 0.11.9 发布,基于 Angular 7 的 UI 组件
查看>>
我就是一个救火员(DBA救援)
查看>>
Centos7安装Gitlab10.0
查看>>
Windows Server 笔记(六):Active Directory域服务:域控制器安装
查看>>
discuz X3登录流程分析
查看>>
javascript事件响应
查看>>
用jQuery实现Ajax
查看>>
上传图片预览
查看>>
vim编辑器
查看>>
程序设计的一些原理
查看>>
iTerm的安装以及配置
查看>>
《社交网站界面设计(原书第2版)》——1.7 反模式的重要性
查看>>
lagp,lacp详解
查看>>
LVS之DR模式原理与实践
查看>>
struts2+extjs
查看>>
Apache2.4.33安装无systemctl/service status/state显示
查看>>
全栈数据之数据挖掘的33个知识点整理
查看>>
Docker的系统资源限制及验证
查看>>