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

40,265

Solution 1

you need to complete your where clause..

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..

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

Solution 2

You don't compare your where clause to anything.

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

Share:
40,265
Rushang
Author by

Rushang

Updated on June 24, 2020

Comments

  • Rushang
    Rushang almost 4 years

    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'