如何解决 SQL Server 错误“在预期条件的上下文中指定的非布尔类型的表达式,靠近‘GROUP’”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37987175/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 04:40:43  来源:igfitidea点击:

How to resolve SQL Server error "An expression of non-boolean type specified in a context where a condition is expected, near 'GROUP'"

sqlsql-serversql-server-2008sql-server-2012sql-server-2014

提问by Rushang

This is my query

这是我的查询

INSERT INTO Tbl_DomainWiseStats (subdomainid, tendercount, Type_cat, DisplayText)
    SELECT 
        ' + CAST(@domain_id AS VARCHAR(100)) + '
        , TenderCount
        , ''ByCountry''
        ,Country 
    FROM 
        (SELECT DISTINCT 
             V.Country, 
             COUNT(DISTINCT Sr_No) as TenderCount 
         FROM 
             dbo.viewgetlivetenders V 
         WHERE 
             '+  @Domainquery +' 
         GROUP BY 
             V.Country) a 
ORDER BY  
    TenderCount 

Error message:

错误信息:

[SQLSTATE 42000] (Error 4145) An expression of non-boolean type specified in a context where a condition is expected, near 'GROUP'

[SQLSTATE 42000](错误 4145)在“GROUP”附近的预期条件的上下文中指定的非布尔类型的表达式

回答by TheGameiswar

you need to complete your whereclause..

你需要完成你的where条款..

This causes error:

这会导致错误:

select * from test where id

but not this:

但不是这个:

select * from test where id =1

In your dynamic SQL,below part is causing issue..

在您的动态 SQL 中,以下部分导致问题..

WHERE '+  @Domainquery +' 
                        GROUP BY V.Country 

回答by TanguyB

You don't compare your where clause to anything.

您不会将您的 where 子句与任何内容进行比较。

"WHERE '+ @Domainquery +' "is incomplete, equal it to the value you want to compare.

"WHERE '+ @Domainquery +' "不完整,等于要比较的值。