# How do I specify a different schema for my source at run time?

**URL:** <https://discourse.getdbt.com/t/how-do-i-specify-a-different-schema-for-my-source-at-run-time/561>\
**Category:** Help\
**Tags:** variables, yaml\
**Created:** [September 9, 2019, 4:44pm UTC](https://discourse.getdbt.com/t/how-do-i-specify-a-different-schema-for-my-source-at-run-time/561 "2019-09-09T16:44:38Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![chanwd](https://avatars.discourse-cdn.com/v4/letter/c/b782af/32.png) [@chanwd](https://discourse.getdbt.com/u/chanwd)\
**Post date:** [September 9, 2019, 7:16pm UTC](https://discourse.getdbt.com/t/how-do-i-specify-a-different-schema-for-my-source-at-run-time/561/3 "2019-09-09T19:16:36Z")

</div>

Thanks for taking the time to answer my question so thoroughly and promptly.

I opted for the 2nd option and created a 2nd source to represent my QA database information while also leveraging the aliases to avoid repeating information within the yml file.

I then created a macro that takes two parameters (schema and table) and called it `db_source`.

Something like this:

```auto
{% macro db_source(source_name, table_name) %}

{% if target.name == 'qa' %} 
{{ source(source_name + '_qa', table_name)}}
{% else %}
{{ source(source_name, table_name)}}
{% endif %}

{% endmacro %}

```

And then referencing it in all of my staging table SQL as:

```auto
from {{ db_source('ic', 'fct_table') }}

```

The one thing I do want to point out with the macro is that the expectation is that each of your sources are distinguished by a suffix, so QA should have a section with the same name as production but with `_qa` to distinguish the yml source name.

Something like this:

```auto
sources:
  - name: ic
  - name: ic_qa

```

---

_[View the full topic](https://discourse.getdbt.com/t/how-do-i-specify-a-different-schema-for-my-source-at-run-time/561)._
