我有一个基于一组条件收集信息的查询.基本上我想知道一个位置当天是否支付了超过50美元或评论部分中有“过滤器”一词……
我的查询是:
SELECT Store_Id,Paid_Out_Amount,Paid_Out_Comment,Paid_Out_Datetime,Update_UserName,Till_Number FROM Paid_Out_Tb WHERE (Store_Id = 1929) AND (Paid_Out_Datetime >= DATEADD(day,DATEDIFF(day,GETDATE()) - 1,0)) AND (Paid_Out_Datetime < DATEADD(day,GETDATE()),0)) AND (Paid_Out_Amount > 50) OR (Paid_Out_Comment LIKE N'%' + 'Filter' + '%')
问题是它返回460结果,应该只返回2.
解决方法
您需要将Paid_Out_Amoutn和Paid_Out_Comment条件包装在第二组括号中:
SELECT Store_Id,Till_Number FROM Paid_Out_Tb WHERE (Store_Id = 1929) AND (Paid_Out_Datetime >= DATEADD(day,0)) AND (Paid_Out_Datetime < DATEADD(day,0)) AND ( (Paid_Out_Amount > 50) OR (Paid_Out_Comment LIKE N'%' + 'Filter' + '%') )