dbt-sqlserver error

The problem I’m having

(‘42000’, “[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near the keyword ‘IF’. (156) (SQLMoreResults)”)

The context of why I’m trying to do this

I’m simply trying to load a dim using dbt to a sql 2019 server.

What I’ve already tried

I used --debug and found out that the problem is after this code:

USE [BasesExternas];
EXEC(‘DROP view IF EXISTS “DataBi”.“base_dbt__dbt_tmp__dbt_tmp_vw”;’);

(‘42000’, “[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near the keyword ‘IF’. (156) (SQLMoreResults)”)

So i’ve created a macro:

{% macro drop_specific_view() %}
{% set sql %}
IF OBJECT_ID(‘DataBi.base_dbt__dbt_tmp__dbt_tmp_vw’, ‘V’) IS NOT NULL
BEGIN
DROP VIEW DataBi.base_dbt__dbt_tmp__dbt_tmp_vw;
END;
{% endset %}
{{ return(sql) }}
{% endmacro %}

and added into the model.

{{ config(materialized=‘table’) }}

– Llamar al macro para eliminar la vista si existe

{{ drop_specific_view() }}

– Consulta para crear la tabla

SELECT *

FROM SmarterFinancial.dbo.ModelosSMS

Some example code or error messages

Put code inside backticks
  to preserve indentation
    which is especially important 
      for Python and YAML!