Using tablenames from a config table for joins



  • 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



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




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2