これは技術的には答えではありませんが、これを分析するのに時間がかかったので、投稿することもできます (反対票を投じられるリスクはありますが)。
説明されている動作を再現する方法はありませんでした.
これがシナリオです:
declare @table table ([user id] int) insert into @table values (1),(1),(1),(1),(1),(1),(1),(2),(2),(2),(2),(2),(2),(null),(null)
プレ>以下は、いくつかのクエリとその結果です:
SELECT COUNT(User ID) FROM @table --error: this does not run SELECT COUNT(dsitinct User ID) FROM @table --error: this does not run SELECT COUNT([User ID]) FROM @table --result: 13 (nulls not counted) SELECT COUNT(distinct [User ID]) FROM @table --result: 2 (nulls not counted)
プレ>そして興味深いこと:
SELECT user --result: 'dbo' in my sandbox DB SELECT count(user) from @table --result: 15 (nulls are counted because user value is not null) SELECT count(distinct user) from @table --result: 1 (user is the same value always)
プレ>説明どおりにクエリを実行できるのは非常に奇妙です。さらに支援を得るには、テーブル構造とデータをお知らせください。