与OR语句结合使用的正确语法是什么

时间:2018-12-10 19:36:44

标签: sql syntax

任何人都可以使用此语法吗?我收到错误消息

and ((a.admit_date between @period1_claim_start and @period1_claim_end and a.paid_date <= @period1_paid_date)
        or (a.admit_date between @period2_claim_start and @period2_claim_end and a.paid_date <= @period2_paid_date))
        and a.SVC_TYP_DESC <>'BH' --!! IS THAT OKAY TO REMOVE BH FROM INPATIENT???
        and ((e.EFFPER between @period1_claim_start and @period1_claim_end 
        or (e.effper between @period2_claim_Start and @period2_claim_end))

2 个答案:

答案 0 :(得分:0)

删除了不必要的括号:

and 
(
    (a.admit_date between @period1_claim_start and @period1_claim_end and a.paid_date <= @period1_paid_date) 
    or 
    (a.admit_date between @period2_claim_start and @period2_claim_end and a.paid_date <= @period2_paid_date)
) 
and 
    a.SVC_TYP_DESC <>'BH' 
and 
(
    e.EFFPER between @period1_claim_start and @period1_claim_end 
    or 
    e.effper between @period2_claim_Start and @period2_claim_end
)

答案 1 :(得分:0)

对于初学者来说,您在声明中缺少最后一个结局

您有6个(和5个)

调整:

和(  (介于@ period1_claim_start和@ period1_claim_end之间的a.admit_date和a.paid_date <= @ period1_paid_date之间的)   要么  (a.admit_date在@ period2_claim_start和@ period2_claim_end之间,而a.paid_date <= @ period2_paid_date) )

和a.SVC_TYP_DESC <>'BH' -!!可以将BH从患者那里移除吗?

和(  (例如,@ period1_claim_start和@ period1_claim_end之间的EFFPER    或(例如,@ period2_claim_Start和@ period2_claim_end之间的effper)  ) )

但除此之外,除非您告诉我们,否则我们不知道您还有其他错误消息。

我们几乎也无法告诉您什么括号是有效的,而不是因为我们不知道您的业务案例。