SQL视图创建错误

时间:2012-11-07 12:11:28

标签: sql sql-server sql-server-2005

我正在尝试将视图从一个数据库复制到另一个数据库并收到错误:

  

消息4121,级别16,状态1,过程vwPAProjects_Summary_New_2   第2行   找不到列“dbo”或用户定义的函数或   聚合“dbo.GetContractName”,或名称不明确

我复制的观点是:

USE [GRAUD]
GO
/****** Object:  View [dbo].[vwPAProjects_Summary_New_2]    Script Date: 11/07/2012 11:57:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[vwPAProjects_Summary_New_2] AS 
select
 dbo.GetContractName(PAPROJNUMBER) 'CONTRACT',
PACONTNUMBER,
isnull(dbo.GetEmployeeName(PABusMgrID),dbo.GetContractPartner(PACONTNUMBER)) 'Project Manager ID',
case PASTAT
when 1 then 'Open'
else 'Closed'
end 'Status',
case PAProjectType
when 3 then 'Fixed Price'
else 'Time and Materials'
end 'Project Type',
PAProject_Fee_Amount 'Project Fee Amount',
PAFTotalCost 'Forecast Total Cost',
(PAProject_Fee_Amount - PAFTotalCost) 'Forcast Profit',
case
    when PAProject_Fee_Amount = 0 then '0.00%'
    else cast(cast(((PAProject_Fee_Amount - PAFTotalCost)/PAProject_Fee_Amount)*100 as decimal(19,2)) as varchar(21)) + '%'
end 'Forcast %',
PAPostedBillingsN 'Actual Billings',
PAPostedTotalCostN 'Actual Total Cost',
(PAPostedBillingsN - PAPostedTotalCostN) 'Current Actual Profit',
case
    when PAPostedBillingsN = 0 then '0.00%'
    else cast(cast(((PAPostedBillingsN - PAPostedTotalCostN)/PAPostedBillingsN)*100 as decimal(19,2)) as varchar(21)) + '%'
end 'Current %'

from PA01201
where PASTAT = 1

有人可以建议我如何复制这个吗?我复制了它之后,它已经在其他数据库上工作了但我看不出有什么差别可以阻止它吗?

1 个答案:

答案 0 :(得分:2)

首先复制函数dbo.GetContractName,然后你也应该找到视图副本。