请帮我按此查询排序:
WHERE
RECEIPT_DATE BETWEEN( Coalesce(@FROM_DATE,RECEIPT_DATE) AND Coalesce(@TO_DATE,RECEIPT_DATE) )
AND
OFFICE_ID=Coalesce(@OFFICE_ID,OFFICE_ID)
错误:关键字“AND”附近的语法不正确。
答案 0 :(得分:2)
试试这个:
WHERE
RECEIPT_DATE BETWEEN
Coalesce(@FROM_DATE, RECEIPT_DATE) AND Coalesce(@TO_DATE, RECEIPT_DATE)
AND
OFFICE_ID = Coalesce(@OFFICE_ID, OFFICE_ID)
您需要在BETWEEN
(BETWEEN Date1 AND Date2
)后面加上两个日期,并且没有括号。
答案 1 :(得分:1)
检查此查询是否正常,没有错误
declare @FROM_DATE datetime
declare @TO_DATE datetime
declare @OFFICE_ID int
select * from table1 WHERE
(RECEIPT_DATE BETWEEN Coalesce(@FROM_DATE,RECEIPT_DATE) AND Coalesce(@TO_DATE,RECEIPT_DATE) )
AND
OFFICE_ID=Coalesce(@OFFICE_ID,OFFICE_ID)
你的where子句中的错误是
BETWEEN (
因为你不能放(在BETWEEN之后。
答案 2 :(得分:1)
BETWEEN
是关键字,而不是函数,因此不带括号。如果您发现AND
混乱的位置,请尝试包装整个逻辑构造。
WHERE (X BETWEEN A AND B) AND (Y = C)