Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

徵狀

請試想下列案例:

  • 您的電腦已安裝 Microsoft SQL Server 2012。

  • 您的查詢包含SELECT語句中的case語句,以及GROUP BY語句中的case語句。

  • 兩個 CASE 語句評估為 Null。

  • 您執行查詢。

在此案例中,您收到下列錯誤訊息:

Msg 8120、Level 16、State 1、Line 3Column "<column name>" 在 select 清單中無效,因為它不包含在 aggregate 函數或 group by 子句中。

例如,您執行下列查詢:create database testgouse testgocreate table tvt ( v1t binary(1) null)create table tln (ln numeric(5) not null)goselectcase when 1=2 then t1.col1else 10end,casewhen t1.col1 = 2 then t1.col2endfrom (select t2.v1t as col1, 10 as col2 from tvt t2) t1group by case when 1=2 then t1.col1else 10end,casewhen t1.col1 = 2 then t1.col2endgo 在查詢中,語句 "1 = 2 之後,t1. col1 else 10" 的計算結果為10。 當您使用 Null 取代 "10" 時,就會發生此問題。注意如果您從SELECT語句或GROUP BY語句移除其中一個CASE語句,就不會發生這個問題。

每個新的 SQL Server 累計更新都包含所有的修正程式,以及前一個累積更新中所包含的所有安全性修正程式。 查看 SQL Server 的最新累計更新:

狀態

Microsoft 已確認<適用於>一節所列的 Microsoft 產品確實有上述問題。

Need more help?

Want more options?

探索訂閱權益、瀏覽訓練課程、瞭解如何保護您的裝置等等。

社群可協助您詢問並回答問題、提供意見反應,以及聆聽來自具有豐富知識的專家意見。

Was this information helpful?

How satisfied are you with the translation quality?
What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×