drop temporary table if exists tempdb.outcome;
if ('2017-01-01' >= @TSTARTDATE AND @TSTARTDATE < '2018-09-23' ) THEN
CREATE temporary TABLE IF NOT EXISTS tempdb.outcome
select distinct
row_id, odr_item_row_id, region_id, createdby, mdn, product_id, billling_acct_id, order_num,
order_entry_ts, install_dt, curr_sts_dt, valid_dt, prov_dt, product, order_type,order_reason,
odr_act_base, datarate , pkg,
max(new_priceplan ) New_PricePlan, max(old_priceplan) Old_PricePlan,
replace(replace(max(new_priceplan ),'_Old',''),' ', '') as New_PricePlan_fj ,
replace(replace(max(old_priceplan),'_Old',''),' ', '') as Old_PricePlan_fj,
UPFRNT_AMT
from tablea
WHERE ORDER_ENTRY_date >=@TSTARTDATE AND ORDER_ENTRY_date <@TENDDATE
and product = 'Broadband'
and order_type in ('new order', 'modify order','terminate order')
and odr_act_base in ('Add','Update', 'delete')
group by row_id, odr_item_row_id, region_id, createdby, mdn, product_id, billling_acct_id, order_num,
order_entry_ts , install_dt, curr_sts_dt, valid_dt, prov_dt, product, order_type,order_reason,
odr_act_base, datarate,pkg ;
这是错误消息:如果('2017-01-01'> = @TSTARTDATE AND @TSTARTDATE 如果不存在则创建临时表tempdb.outcome选择不同的row_id,odr_item_row_id,region_id,创建者,mdn,product_id,billling_acct_id,order_num,order_entry_ts,install_dt,curr_sts_dt,valid_dt,prov_dt,产品,order_type,order_reason,odr_act_base,datarate,pkg,max(new_priceplan)New_PricePlan,max(old_priceplan)Old_PricePlan,将replace(replace(max(new_priceplan),'_ Old',''),'','')作为New_PricePlan_fj,replace(replace(max(old_priceplan),'_ Old',''),'','')为Old_PricePlan_fj,UPFRNT_AMT来自ptclsatmap_archival
。ptclsales.orders_20161001_20180923
WHERE ORDER_ENTRY_date> = @ TSTARTDATE AND ORDER_ENTRY_date = @TSTARTDATE AND @TSTARTDATE
在行1 0.000秒处创建'
有人可以帮我调试以下if语句吗?如果存在tempdb.outcome,它会给我错误删除临时表;如果('2017-01-01'> = @TSTARTDATE AND @TSTARTDATE
您应在分组结果中不涉及的所有列中分组提及(在您错过的代码中,New_PricePlan_fj和Old_PricePlan_fj)
CREATE temporary TABLE IF NOT EXISTS tempdb.outcome
select row_id
, odr_item_row_id
, region_id
, createdby
, mdn
, product_id
, billling_acct_id
, order_num
, order_entry_ts
, install_dt
, curr_sts_dt
, valid_dt
, prov_dt
, product
, order_type
, order_reason
, odr_act_base
, datarate
, pkg
, max(new_priceplan ) New_PricePlan
, max(old_priceplan) Old_PricePlan
, replace(replace(max(new_priceplan ),'_Old',''),' ', '') as New_PricePlan_fj
, replace( replace(max(old_priceplan),'_Old',''),' ', '') as Old_PricePlan_fj
,UPFRNT_AMT
from tablea
WHERE ORDER_ENTRY_date >=@TSTARTDATE AND ORDER_ENTRY_date <@TENDDATE
and product = 'Broadband'
and order_type in ('new order', 'modify order','terminate order')
and odr_act_base in ('Add','Update', 'delete')
group by row_id
, odr_item_row_id
, region_id
, createdby
, mdn
, product_id
, billling_acct_id
, order_num
, order_entry_ts
, install_dt
, curr_sts_dt
, valid_dt
, prov_dt
, product
, order_type
, order_reason
, odr_act_base
, datarate
, pkg
, New_PricePlan_fj
, Old_PricePlan_fj;
您不需要区分,因为您有一个分组依据(这不是错误,但是区分是没有用的]