我正在尝试从表中创建MS SQL服务器中的视图。表名是Account_Plan,我试图创建一个Account_Plan_vw视图。在执行DDL创建视图时,我收到错误,如下所示。
Msg 258,Level 15,State 1,Procedure Account_Plan_vw,Line 56
无法在ntext上调用方法Msg 207,Level 16,State 1,Procedure Account_Plan_vw,Line 22
列名称“How_the_CU_will_achieve_these_objective2__c”无效。
错误消息显示“How_the_CU_will_achieve_these_objective2__c”列无效。但是,这是ntext类型的Account_Plan表中的有效列。
有人可以帮忙吗?我刚刚从Create视图语句中删除了多余的列。
CREATE VIEW [dbo].[Account_Plan_vw]
AS
SELECT
Results_1.Account__c
,Results_1.How_the_CU_will_achieve_these_objectives__c
,Results_1.How_the_CU_will_achieve_these_objective2__c
FROM
(
SELECT ROW_NUMBER() OVER (PARTITION BY apc1.Account__c ORDER BY apc1.Year__c DESC, apc1.CreatedDate DESC) AS RN_1
,apc1.Account__c
,apc1.How_the_CU_will_achieve_these_objectives__c
,apc1.How_the_CU_will_achieve_these_objective2__c
FROM Account_Plan apc1
INNER JOIN RecordType rtp1
ON apc1.RecordTypeId=rtp1.[Id]
AND rtp1.DeveloperName = 'Account_Plan'
INNER JOIN Account acc1
ON acc1.[Id] = apc1.Account__c
WHERE apc1.Year__c <= YEAR(GETDATE())
) AS Results_1
WHERE RN_1 = 1
答案 0 :(得分:1)
不推荐使用NTEXT,而是将其转换为NVARCHAR(MAX)
请参阅:ntext, text, and image (Transact-SQL)
您应该考虑更改表格,而不仅仅是在视图中投射,而是:
CREATE VIEW [dbo].[Account_Plan_vw]
AS
SELECT
results_1.Account__c
, results_1.How_the_CU_will_achieve_these_objectives__c
, results_1.How_the_CU_will_achieve_these_objective2__c
FROM (
SELECT
ROW_NUMBER() OVER (PARTITION BY apc1.Account__c ORDER BY apc1.Year__c DESC, apc1.CreatedDate DESC) AS rn_1
, apc1.Account__c
, apc1.How_the_CU_will_achieve_these_objectives__c
, cast(apc1.How_the_CU_will_achieve_these_objective2__c as nvarchar(max)) as How_the_CU_will_achieve_these_objective2__c
FROM Account_Plan apc1
INNER JOIN RecordType rtp1 ON apc1.RecordTypeId = rtp1.[Id]
AND rtp1.DeveloperName = 'Account_Plan'
INNER JOIN Account acc1 ON acc1.[Id] = apc1.Account__c
WHERE apc1.Year__c <= YEAR(GETDATE())
) AS results_1
WHERE RN_1 = 1
答案 1 :(得分:1)
问题,找到它有点神秘。 salesforce对象有一个字段last_peer_review_date__c,没有权限给任何人。因此,当我使用SF_Replicate命令时,DBAMP用户无法看到该字段,因此错过了在SQL Server中创建此字段。创建视图SQL是我几周前创建的,当时它确实有效。现在,当我使用相同的SQL时,它失败了,因为SQL有last_peer_review_date字段,但Account_Plan表没有。
Balaji Pooruli