0
SELECT
    $model_master_id$,
    $model_market_segment$,
    $country$,
    $ctry_cd$,
    $score_run_id$,
    $period_id$,
    $prediction_from_dt$,
    $prediction_to_dt$,
    $buy_acq$,
    $eval_prd$,
    $scr.model_score$,
    $scr.model_score_bin$
    from 
    (select 
    model_master_id,
    model_version_id,
    score_run_id,
    $site_rsdnc_id$,
    segment_name,
    model_score,
    model_score_bin
    FROM $master_scoring_table_name$) scr
    LEFT JOIN
    (SELECT
    $site_rsdnc_id$,
    $segment_column_name$ 
    FROM $feature_table_name$) f 
    ON f.$site_rsdnc_id$=scr.$site_rsdnc_id$;

Could there be a possibly simple way to achieve the above code from my attached excel Config other than dynamic sql? Everything within dollar quotes comes from my config. I tried dynamic sql with for loops but since I have multiple tablenames coming from my config the dynamic sql runs for a very long time.

enter image description here

2
  • Are you sure that the performance problems origins from the dynamic part? I.e. does the query perform well if you replace "wildcards" with static values? Feb 4, 2022 at 8:17
  • Yeah because the way I had created the dynamic sql is using a for loop where each row in this config is fed as a record. So, for around 130 such rows the sql runs quite long. For just a single static tablename and columnname value, it runs in like 10-12 sec Feb 4, 2022 at 9:40

1 Answer 1

0

No, you need dynamic SQL if table and column names are variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.