FB3.0 Dateadd() throws syntax error in where section of query - firebird

I am trying to compare the date modified (field type: Timestamp) with a value that is based off of a month before the current date. I keep getting a syntax error when using the function DateAdd().
I Am Using Libreoffice base 6.2.3.2 (x64) and firebird 3.0 embedded
Using this code, I get a result returning no records but no error
Select *
From "tblPart"
Where "Date Modified" = Current_Timestamp
but anytime I want to use the Dateadd() function, I get an error
Select *
From "tblPart"
Where
"Date Modified"< Dateadd(Month,-1,Current_Timestamp)
Expected to Return a list of results that have been modified over a month ago.
Errors:
SQL Status: HY000
Error code: 1000
Syntax error in SQL statement
SQL Status: HY000
Error code: 1000
SQL Status: HY000
Error code: 1000
syntax error, unexpected $end, expecting BETWEEN or IN or SQL_TOKEN_LIKE
//EDIT: Added the programs that I used

I ran into the same problem. Though the SQL-statement with DateAdd() has been suggested as working, LO Base answered the query with a message box
Syntax error in SQL statement
Why it should work
In contrast the same SQL statement like in the query succeeded by running it in the "Execute SQL Statement" window (LO Base' main window menu "tools" > "SQL…").
Solution
What finally got my query to work was to check "Run SQL command directly" in the toolbar or in the "Edit" menu.
This prevents LO from analyzing the SQL query before execution. This fails, because it is not understanding the full SQL statement (firebird's DateAdd()-function), and thus is the reason for the mentioned errors.

Related

How to correct use $X in jasper??. Problem with parameters and IN clause in JSS

I have a report made with Jaspersoft Studio and in the dataset query I need to use an IN clause, for that I am using the expression "$X{IN ..."
Question # 1: What is the correct type to use for the parameter?
I'm using the following format:
Question # 2: How do I test in the preview?
Parameters screen:
To help, follow the excerpt of where with the parameter being used:
"...Where (($X{IN, db.empresa, paramIdEmpresa}) OR $ P!{ParamIdEmpresa} IS NULL) and (db_view ... "
Error that appears in the preview with the above parameters:
net.sf.jasperreports.engine.JRException: Error executing SQL statement
for: unit1. at com.jaspersoft.studio.editor.preview.view.control.ReportController.fillReport
(ReportController.java:551) at com.jaspersoft.studio.editor.preview.view.control.ReportController.access
(BaseFillHandle.java:135) at java.lang.Thread.run (Thread.java:748)
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at
or near "["   Position: 199 at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse
(QueryExecutorImpl.java:2440) at
org.postgresql.core.v3.QueryExecutorImpl.processResults
the problem was in the query and not in jasper...
the correct query is:
where
(($X{IN,db.idempresa, paramIdEmpresa}) OR db.idempresa IS NULL )
thanks to GP...
The best possible way to solve it is simple:
create a parameter called $P!{paramWhere}. of your application
pass the complete where clause with this parameter, e.g. "id = 200"
In your query inside jasper, you put it like this: "... select * from <anywhere> where $P!{paramWhere} ..." and it will magically work.

How to eliminate Query error: 403 in Grafana? Example is a Substring

I'm trying to receive a result similiar to '13:49:31' in this panel. Here is the code:
select SUBSTRING(CONVERT(VARCHAR,DATEADD(HOUR,-3,SYSDATETIME())),12,8)
This is the message: "Query error: 403"
I copied the code and executed it at SQL Server Management Studio and it worked.
If I remove the substring function, it works. Like this "select CONVERT(VARCHAR,DATEADD(HOUR,-3,SYSDATETIME()))"
However, I really need this format '13:49:31'

Sum(Field) Where Condition=Value

I'm trying to find how should be the correct syntax for Sum(FIELD) where field Condition=Value
I'm using this code;
if ({VatCodes.VatValue} =12) then Sum({InventoryTransTemp.Price})
The problem is that this syntax works but for all my report fields and either contain this value or not.My syntax in sql server is Select Sum(InventoryTransTemp.Price) where Vatcodes.VatValues=12.
How should i write it for succedd my desired result?

ERROR: invalid input syntax for type numeric: "N/A" ... nice but which column?

I am running a function in PostgreSQL which contains several functions which purpose is to load data from foreign tables into mine. While running I get this error:
[SELECT - 0 row(s), 762.353 secs] [Error Code: 0, SQL State: 22P02] ERROR: invalid input syntax for type numeric: "N/A"
Where: PL/pgSQL function import_data_3(integer,timestamp with time zone,timestamp with time zone,integer) line 16 at SQL statement
SQL statement "SELECT import_data_3(import, beg, end_t, is_l)"
PL/pgSQL function data_import_all(timestamp with time zone,timestamp with time zone,integer,integer) line 31 at PERFORM
I know what that means and also its reason I am trying to convert 'N/A' string to number and there for this error, problem is this lousy error does not specify the column where the error occurred.
Is there a way to get more precise error message which would tell me the exact column where the error happened?
It's not in the column but in one of the parameters that are passed to import_data_3.
You called the query SELECT import_data_3(import, beg, end_t, is_l).
The specification of this function is import_data_3(integer,timestamp with time zone,timestamp with time zone,integer)
Since you got the error
invalid input syntax for type numeric: "N/A"
this most likely means that either first parameter "import" or the last one "is_l" contain the value "N/A". Try to debug the calling code of the function data_import_all and see how those two parameter values are generated.

Getting an error when using a date parameter

I am using iReport 5.0.1. I created a date parameter and am using it in my query:
When I preview the report, I enter my date parameter:
After I enter all the parameters and run the report, I get this error:
Error filling print... Error executing SQL statement for : Sample
net.sf.jasperreports.engine.JRException: Error executing SQL statement for : Sample
at com.jaspersoft.jrx.query.PlSqlQueryExecuter.createDatasource(PlSqlQueryExecuter.java:143)
at net.sf.jasperreports.engine.fill.JRFillDataset.createQueryDatasource(JRFillDataset.java:1086)
at net.sf.jasperreports.engine.fill.JRFillDataset.initDatasource(JRFillDataset.java:667)
at net.sf.jasperreports.engine.fill.JRBaseFiller.setParameters(JRBaseFiller.java:1258)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:877)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:822)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:61)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:446)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:276)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:745)
at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:891)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997)
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "Feb"
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1592)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1327)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:192)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:350)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:254)
at com.jaspersoft.jrx.query.PlSqlQueryExecuter.createDatasource(PlSqlQueryExecuter.java:136)
... 12 more
Print not filled. Try to use an EmptyDataSource...
What is going on here, and how do I fix this? Thanks!
I think the ! in $P!{...} means to include the parameter's literal value in the report.
Try using $P{start_date} and $P{end_date}, both without the !.
Effectively, your SQL statement is using:
and finalinsdate >= Feb/18/2013
That is not a valid SQL statement, which means PostgreSQL will complain with:
org.postgresql.util.PSQLException: ERROR: syntax error at or near "Feb"
For next time, copy and paste the source code, instead of taking a screen capture.