select 语句执行时没有错误或警告。
更新语句引发错误:
关键字“组”附近的语法不正确。
select [sSVsys].[textUniqueWordCount], count(*) as [actCount]
from [docSVsys] as [sSVsys]with (nolock)
join [FTSindexWordOnce] with (nolock)
on [sSVsys].[sID] = [FTSindexWordOnce].[sID]
where [sSVsys].[sID] < 500000
group by [sSVsys].[sID], [sSVsys].[textUniqueWordCount]
having [sSVsys].[textUniqueWordCount] <> count(*)
update [sSVsys]
set [sSVsys].[textUniqueWordCount] = count(*)
from [docSVsys] as [sSVsys]with (nolock)
join [FTSindexWordOnce] with (nolock)
on [sSVsys].[sID] = [FTSindexWordOnce].[sID]
where [sSVsys].[sID] < 500000
group by [sSVsys].[sID], [sSVsys].[textUniqueWordCount]
having [sSVsys].[textUniqueWordCount] <> count(*)
如果答案是加入派生表,那么我可以弄清楚。
现有更新是否存在语法错误?
这个派生表有效
update [docSVsys]
set [docSVsys].[textUniqueWordCount] = [WordOnce].[actCount]
from [docSVsys]
join
( select [FTSindexWordOnce].[sID], count(*) as [actCount]
from [FTSindexWordOnce] with (nolock)
-- where [FTSindexWordOnce].[sID] < 1500000
group by [FTSindexWordOnce].[sID] ) as [WordOnce]
on [docSVsys].[sID] = [WordOnce].[sID]
and [docSVsys].[textUniqueWordCount] <> [WordOnce].[actCount]
对于更好的方法,我会保留几天的任何评论或答案,然后删除。这种方法在现有的 SO 答案中。