开发者

DBT : For loop for 2 variable simultaneously

开发者 https://www.devze.com 2022-12-07 20:41 出处:网络
My Sample code is : {%-set VARIABLE = ["123","1234"]-%} {%-set VARIABLE1 = ["abc","def"]-%}

My Sample code is :

{%-    set VARIABLE = ["123","1234"]    -%}
{%-    set VARIABLE1 = ["abc","def"]    -%}
with FINAL as (
    
    {% for (col,col1) in (VARIABLE,VARIABLE1) %}

      Select
     开发者_Go百科 current_date as date,
    
       {{ col }} as test1,
       '{{ col1 }}' as test2
     
       UNION ALL
     
    {% endfor %}
  select current_date as date1,
  'Temp' as test1,
  'Temp' as test2
) select * from FINAL

Output I am getting :

create or replace  view Test.CRS_Foundation.test_for
  
   as (
    with FINAL as (
    
    

      Select
      current_date as date,
    
       123 as test1,
       '1234' as test2
     
       UNION ALL
     
    

      Select
      current_date as date,
    
       abc as test1,
       'def' as test2
     
       UNION ALL
     
    
  select current_date as date1,
  'Temp' as test1,
  'Temp' as test2
) select * from FINAL
  );

Expected Output :

create or replace  view Test.CRS_Foundation.test_for
  
   as (
    with FINAL as (
    
    

      Select
      current_date as date,
    
       123 as test1,
       'abc' as test2
     
       UNION ALL
     
    

      Select
      current_date as date,
    
       1234 as test1,
       'def' as test2
     
       UNION ALL
     
    
  select current_date as date1,
  'Temp' as test1,
  'Temp' as test2
) select * from FINAL
  );

Is there anything i missed in code, code is running fine but output is not as expected Is there anything i missed in code, code is running fine but output is not as expected Is there anything i missed in code, code is running fine but output is not as expected

0

精彩评论

暂无评论...
验证码 换一张
取 消