error occured : “Cannot call methods on nvarchar.”

こ雲淡風輕ζ 提交于 2020-06-25 05:35:03

问题


I wrote a query to find answers related to a specific question, but I received this error when runing this code.

Cannot call methods on nvarchar

 select Posts.Id as Answer, ParentId as question, User.DisplayName as Answerer 
 FROM  Posts
INNER JOIN Users    ON Posts.OwnerUserId = Users.Id
WHERE 
ParentId in (SELECT Posts.Id
FROM  Posts
INNER JOIN PostTags ON Posts.Id          = PostTags.PostId
INNER JOIN Tags     ON PostTags.TagId    = Tags.id
INNER JOIN Users    ON Posts.OwnerUserId = Users.id
INNER JOIN PostTypes ON Posts.PostTypeId = PostTypes.Id
WHERE Tags.TagName   in 
(select 
   num.TagName as Tag

 from

(select TagName
from
Tags, PostTags, Posts
where Tags.Id = PostTags.TagId and Posts.Id = PostId
and Posts.CreationDate < '2015-04-20'
and Posts.CreationDate > '2015-01-01'
group by TagName) as rate

INNER JOIN
(select TagName 
from Tags, PostTags, Posts
where Tags.Id = PostTags.TagId and Posts.Id = PostId
group by TagName
having count(PostId) > 8000)as num 
ON rate.TagName = num.TagName
)
  AND Posts.AnswerCount > 1
  AND Posts.AcceptedAnswerId is not null
  AND Posts.Score > 0
  AND Posts.PostTypeId  = 1                -- PostTypeId = 1 -> Question
  AND Posts.CommunityOwnedDate is null
  )
AND Posts.PostTypeId  = 2                -- -> Answers

I think the problem is ParentId , but I do not understand what is wrong.


回答1:


You have a reserved word User in your query:

select Posts.Id as Answer, ParentId as question, User.DisplayName as Answerer

You will need to modify it to be [User].DisplayName

Here is a great resource on reserved words in SQL: https://www.drupal.org/node/141051



来源:https://stackoverflow.com/questions/29853631/error-occured-cannot-call-methods-on-nvarchar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!