Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlserver__dateadd() does not work on Synapse #68

Open
dataders opened this issue Nov 9, 2021 · 0 comments
Open

sqlserver__dateadd() does not work on Synapse #68

dataders opened this issue Nov 9, 2021 · 0 comments

Comments

@dataders
Copy link
Contributor

dataders commented Nov 9, 2021

for some reason sqlserver__dateadd works on Azure SQL, but on Synapse, it comes up short by a day.

actual expected
1900-01-02 00 00 00.0000000 1900-01-01 00 00 00.000

{% macro sqlserver__dateadd(datepart, interval, from_date_or_timestamp) %}
dateadd(
{{ datepart }},
{{ interval }},
cast({{ from_date_or_timestamp }} as datetime)
)
{% endmacro %}
{% macro synapse__dateadd(datepart, interval, from_date_or_timestamp) %}
{% do return( tsql_utils.sqlserver__dateadd(datepart, interval, from_date_or_timestamp)) %}
{% endmacro %}

with data as (

    select * from "dbtsynapseci"."test"."data_dateadd"

)

select
    case
        when datepart = 'hour' then cast(

    dateadd(
        hour,
        interval_length,
        cast(from_time as datetime)
        )

 as 
    
    
    datetime2
)
        when datepart = 'day' then cast(

    dateadd(
        day,
        interval_length,
        cast(from_time as datetime)
        )

 as 
    
    
    datetime2
)
        when datepart = 'month' then cast(

    dateadd(
        month,
        interval_length,
        cast(from_time as datetime)
        )

 as 
    
    
    datetime2
)
        when datepart = 'year' then cast(

    dateadd(
        year,
        interval_length,
        cast(from_time as datetime)
        )

 as 
    
    
    datetime2
)
        else null
    end as actual,
    result as expected

from data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant