Skip to Content

ADS 12 bug using the result of TIMESTAMPDIFF for a calculation

Under certain circumstances a calculation using the result of TIMESTAMPDIFF results in error 5070 "The given data type is not valid for the requested operation. Expected a numeric value. Field: "EXPR"":

declare @d1 date;
declare @d2 date;
set @d1 = current_date();
set @d2 = @d1;

select TIMESTAMPDIFF(SQL_TSI_DAY, @d1, @d2) / 1.5 from system.iota; -- error 5070

select TIMESTAMPDIFF(SQL_TSI_DAY, @d1, @d2) * 1.5 from system.iota; -- pass

select TIMESTAMPDIFF(SQL_TSI_DAY, '2015-01-01', @d2) / 1.5 from system.iota; --pass

select TIMESTAMPDIFF(SQL_TSI_DAY, @d1, '2015-01-01') / 1.5 from system.iota; -- pass

select TIMESTAMPDIFF(SQL_TSI_DAY, '2015-01-01', '2015-01-01') / 1.5 from system.iota; -- pass

Same error occures if I use current_date() or a database field instead of a script variable:

select TIMESTAMPDIFF(SQL_TSI_DAY, current_date(), current_date()) / 1.5 from system.iota; -- error 5070

- but -

select TIMESTAMPDIFF(SQL_TSI_DAY, current_date()+1, current_date()) / 1.5 from system.iota; -- pass

- and strange enough -

if I change "set @d2 = @d1;" to "set @d2 = @d1+1;" the error disappears (but not for +0!).

Syntax Check of ARC SQL window shows "Success" in all cases!

To circumvent this error, one can CAST the result of TIMESTAMPDIFF to SQL_DOUBLE.

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Dec 04, 2017 at 08:31 AM

    With Service Pack 2 the error is gone.

    Good work!

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.