出现错误:"无法调用nvarchar."上的方法 [英] error occured : "Cannot call methods on nvarchar."

查看:17
本文介绍了出现错误:"无法调用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作为答案,选择ParentID作为问题,选择User.DisplayName作为 应答者

您需要将其修改为[User].DisplayName

这里有一个关于SQL中保留字的很好的资源:https://www.drupal.org/node/141051

这篇关于出现错误:&quot;无法调用nvarchar.&quot;上的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆