SELECT Failed 3706: Синтаксическая ошибка: ожидается что-то среднее между - PullRequest
0 голосов
/ 20 июня 2020

Новичок был бы очень признателен за помощь в следующем сообщении об ошибке 3706: ожидалось что-то между словом 'Calls' и ключевым словом 'case'

SELECT distinct
b.emp_nbr,
b.prim_terr_desc, 
a.sales_terr_nbr,
TRIM (B.first_nm) ||' '|| TRIM (B.last_nm) as AE_Name,

count (distinct call_nbr) as Calls

case    (when   a.sale_call_chanl_desc LIKE 'Face to Face%' then 'F2F'
            when a.sale_call_chanl_desc = 'Telephone' then 'Phone'
            when a.sale_call_chanl_desc LIKE 'Web Meeting%' then 'Web_Meeting'
            end) as Channel
        
FROM isell_prod_view_db.sfdc_call_action a
LEFT OUTER JOIN  isell_prod_view_db.sfdc_customer_info c ON (a.cust_acct_nbr = c.cust_acct_nbr and a.rec_delt_flg = 'N')
LEFT OUTER JOIN isell_prod_view_db.sfdc_opportunity d ON (d.cust_acct_nbr = c.cust_acct_nbr and  d.delt_flg = 'N')
LEFT OUTER JOIN isell_prod_view_db.sfdc_user_profile b ON a.crte_by_user_key_nbr = b.user_key_nbr
LEFT OUTER JOIN isell_prod_view_db.sfdc_opportunity_item e ON  (e.oprty_key_nbr = d.oprty_key_nbr and e.delt_flg = 'N')

where a.sale_call_stat_desc = 'Completed'
 
and a.sales_div_nbr = '8'
and a.sales_grp_nbr = '9'
and a.sales_org_nbr ='30'
and b.prim_terr_desc LIKE ('8-9-30%')
and a.priv_entr_flg='N'
and a.sale_call_chanl_desc is not null
and CAST(a.call_dt AS date format 'MM/DD/YYYY') between '06/01/2019' and '05/31/2020'


group by 1,2,3,4

1 Ответ

0 голосов
/ 23 июня 2020

Я перенастроил код. Это работает. Я думаю, мне нужна была запятая после "AS Channel"

    SELECT distinct
b.emp_nbr,
TRIM (B.first_nm) ||' '|| TRIM (B.last_nm) as AE_Name,
b.prim_terr_desc, 
b.prim_terr_seg_nbr,
            
case    when CAST(a.call_dt AS date format 'MM/DD/YYYY') between '12/01/2019' and '02/29/2020' then 'Q3'
            when CAST(a.call_dt AS date format 'MM/DD/YYYY')  between '03/01/2020' and '05/31/2020' then 'Q4'
            end as Qtr,

count (distinct call_nbr) as Calls

FROM isell_prod_view_db.sfdc_call_action a
LEFT OUTER JOIN  isell_prod_view_db.sfdc_customer_info c ON (a.cust_acct_nbr = c.cust_acct_nbr and a.rec_delt_flg = 'N')
LEFT OUTER JOIN isell_prod_view_db.sfdc_opportunity d ON (d.cust_acct_nbr = c.cust_acct_nbr and  d.delt_flg = 'N')
LEFT OUTER JOIN isell_prod_view_db.sfdc_user_profile b ON a.crte_by_user_key_nbr = b.user_key_nbr
LEFT OUTER JOIN isell_prod_view_db.sfdc_opportunity_item e ON  (e.oprty_key_nbr = d.oprty_key_nbr and e.delt_flg = 'N')

where a.sale_call_stat_desc = 'Completed'
and a.sales_div_nbr = '8'
and a.sales_grp_nbr = '9'
and a.sales_org_nbr ='30'
and b.prim_terr_desc LIKE ('8-9-30%')
and A.rec_delt_flg = 'N'
and A.child_event_flg='N'
and a.priv_entr_flg='N'
and B.prim_terr_seg_desc not in ('No Coverage') 
and A.sale_call_chanl_desc in ('Telephone', 'Phone', 'Face to Face - Appt', 'Face to Face - No Appt', 'Web Meeting')
and B.prim_terr_seg_nbr not in ('3', '8', '25')   

and CAST(a.call_dt AS date format 'MM/DD/YYYY') between '12/01/2019' and '05/31/2020'

group by 1,2,3,4,5
...