如何解决 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
How to resolve SQL Server error "An expression of non-boolean type specified in a context where a condition is expected, near 'GROUP'"
提问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 where
clause..
你需要完成你的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 +' "
不完整,等于要比较的值。