HK007 HK007 - 1 month ago 5
SQL Question

Comparison operator not working sql

I'm using the following code. It is working fine but when I use the date filter it stops working. I have use the comparison operator in sql. I have searched for questions but have not found the desired answer.

SELECT SUM(retailerData.poster), SUM(retailerData.banners), SUM(retailerData.tradeLetters), SUM(retailerData.stickers) ,
SUM(retailerData.buntings),SUM(retailerData.dangler) FROM retailerData INNER
JOIN retailer ON retailer.retailerID=retailerData.retailerID WHERE
'2016-08- 24'<= retailerData.visitDate <='2016-09-03'
AND retailer.retailerID IN( SELECT
retailer.retailerID FROM retailer INNER JOIN office ON office.officeID=
retailer.officeID WHERE office.officeID IN( SELECT officeID FROM office
parentOfficeID IN( SELECT officeID FROM office WHERE parentOfficeID IN
officeID FROM office WHERE officeName='Faisalabad Belt') ) ))

Help me regarding this.


You have this condition:

WHERE '2016-08- 24'<= retailerData.visitDate <= '2016-09-03' 

In most dialects this is not standard -- neither the ternary operator nor the space in the date literal.

Try this:

WHERE '2016-08-24'<= retailerData.visitDate AND
      retailerData.visitDate <= '2016-09-03'