【问题标题】:How do I resolve an "incorrect syntax near ','"?如何解决“',' 附近的语法错误”?
【发布时间】:2016-11-10 10:46:51
【问题描述】:

我正在为一个活动编写查询,每当我尝试运行它时,我都会收到一条错误消息,指出语法不正确。

select
    opp.*
from
(
    select 
        opp.*,
        row_number() over (partition by opp.contact_email_address order by opp.status_date desc) as row_number
    from
        opportunity_data opp
    where
        opp.email_bounced = 'false'
        and opp.email_unsubscribe = 'false'
        and opp.first_mkt_medium not in ('partner', 'inbound_outbound')
        and opp.latest_mkt_medium not in ('partner', 'inbound_outbound')
        and datediff (day, cast(latest_rfq_submitted_date as date), cast(getdate() as date)) > 30
        and opp.on_cover = 'no'
        and opp.primary_group in ('Market_trader', 'Food_stand', 'Mobile_food_van', 'Caterer')
        and opp.site = 'simplybusiness'
        and opp.opportunity_status = ('quote_recieved', 'rfq_submitted', 'policy_expired_not_renewed')
) opp
where row_number = 1

【问题讨论】:

  • 删除一些代码,重试,删除一些代码,重试等等。
  • 请添加完整的错误信息。
  • 欢迎来到 Stack Overflow!为了帮助人们回答您的问题,您需要更具体地说明错误。请edit您的帖子包含您在编译minimal reproducible example时得到的确切错误(最好使用复制+粘贴以避免转录错误)。

标签: sql sql-server salesforce salesforce-service-cloud


【解决方案1】:

检查一下:

select
    opp.*
from
(
    select 
        opp.*,
        row_number() over (partition by opp.contact_email_address order by opp.status_date desc) as row_number
    from
        opportunity_data opp
    where
        opp.email_bounced = 'false'
        and opp.email_unsubscribe = 'false'
        and opp.first_mkt_medium not in ('partner', 'inbound_outbound')
        and opp.latest_mkt_medium not in ('partner', 'inbound_outbound')
        and datediff (day, cast(latest_rfq_submitted_date as date), cast(getdate() as date)) > 30
        and opp.on_cover = 'no'
        and opp.primary_group in ('Market_trader', 'Food_stand', 'Mobile_food_van', 'Caterer')
        and opp.site = 'simplybusiness'
        and opp.opportunity_status in ('quote_recieved', 'rfq_submitted', 'policy_expired_not_renewed')
) opp
where row_number = 1

【讨论】:

    【解决方案2】:

    由于您的最后一行 where 出现错误。你不能这样使用它。我想你想使用in 而不是=

    AND opp.opportunity_status IN ('quote_recieved', 'rfq_submitted', 'policy_expired_not_renewed')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多