Using CURRENT_TIMESTAMP, Arithmetic Operator, and Parameter Using Firebird

Why this does not work (when the parameter is set to 1):

SELECT * FROM TABLE WHERE TIMESTAMPFIELD > (CURRENT_TIMESTAMP - ?) 

But it works:

 SELECT * FROM TABLE WHERE TIMESTAMPFIELD > (CURRENT_TIMESTAMP - 1) 

I get the error message: "conversion error from string "39723.991882951" "

I am using Firebird 2.1

EDIT:

I found the answer myself with a little help:

 SELECT * FROM TABLE WHERE TIMESTAMPFIELD > (CURRENT_TIMESTAMP - CAST(? as DECIMAL(18,9)) 

It works if the parameter is set as a floating point value.

+4
source share
1 answer

What do you want to do exactly? Perhaps I can be more helpful with more details.

SELECT * FROM TABLE WHERE TIMESTAMPFIELD> (CURRENT_TIMESTAMP -?)

How do you set your parameter in your code? What language do you use?

If you are using Delphi, then your parameter should be passed as a Float. I.e:

 MyQuery.ParamByName('delta').asFloat := 0.1; 

Try this and let us know if it works.

NTN

+2
source

Source: https://habr.com/ru/post/1277416/


All Articles