簡體   English   中英

發生錯誤:“無法在nvarchar上調用方法。”

[英]error occured : “Cannot call methods on nvarchar.”

我寫了一個查詢來查找與特定問題相關的答案,但是在運行此代碼時收到了此錯誤。

無法在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

我認為問題是ParentId ,但我不明白出了什么問題。

您的查詢中有一個保留字User

選擇Posts.Id作為Answer,ParentId作為問題,User.DisplayName作為Answerer

您需要將其修改為[User].DisplayName

這是SQL中保留字的一個很好的資源: https//www.drupal.org/node/141051

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM