how to pass variable and string to macro?

Hi,

I would like to use macro returning values depending on parameter like this.

  • macros/fn_get_bar.sql
{% macro fn_get_bar(foo) %} 
{% if foo== 1 %}
    {{return ('aaa')}}
{% else %}
...
{% endif %}
{%- endmacro %}

In this case, how should I call macro in my models to get “aaa” ?

Thanks,

Cinyoung

Hello @hurcy ,

Call it as below as below:
{{fn_get_bar(1)}}

Example in query:

select
id as payment_id,
{{ fn_get_bar(1) }} as payment_description,

from raw_dataset.payments

Regards
Minhaj