Sybase Database Error: Invalid data conversion - sql

I need help with this Query, I'm making some calculations based on some results, but I'm receiving the following error:
Sybase Database Error: Invalid data conversion.
The query is as follows:
SELECT
DC.DIM_DATE.DATE_ID,
DC.DIM_E_RAN_UCELL.RBS_ID,
(SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestDchPsIntRabEstablish)+SUM(DC.DC_E_RAN_UCELL_RAW.pmSumFachPsIntRabEstablish)+SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestPsHsAdchRabEstablish)+SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestPsEulRabEstablish))/720 AS '3G_DATA_ERLANG',
(SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestCs12Establish)+SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestAmr12200RabEstablish)+SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestAmr7950RabEstablish)+SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestAmr5900RabEstablish)+SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestAmr4750RabEstablish)+SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestAmrWbRabEstablish)+SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestAmrNbMmRabEstablish))/720 AS '3G_SPEECH_ERLANG',
(100*(SUM(DC.DC_E_RAN_UCELL_RAW.pmTotNoRrcConnectReqCsSucc)/(1+SUM(DC.DC_E_RAN_UCELL_RAW.pmTotNoRrcConnectReqCs)-SUM(DC.DC_E_RAN_UCELL_RAW.pmNoLoadSharingRrcConnCs))*(SUM(DC.DC_E_RAN_UCELL_RAW.pmNoRabEstablishSuccessSpeech)+SUM(DC.DC_E_RAN_UCELL_RAW.pmNoRabEstablishSuccessCs64)+SUM(DC.DC_E_RAN_UCELL_RAW.pmRabEstablishEcSuccess))/(SUM(DC.DC_E_RAN_UCELL_RAW.pmRabEstablishEcAttempt)+SUM(DC.DC_E_RAN_UCELL_RAW.pmNoRabEstablishAttemptSpeech)+SUM(DC.DC_E_RAN_UCELL_RAW.pmNoRabEstablishAttemptCs64)-SUM(DC.DC_E_RAN_UCELL_RAW.pmNoDirRetryAtt)))) AS '3G_CSSR_CS'
FROM
DC.DIM_DATE,
DC.DIM_TIME,
DC.DIM_E_RAN_UCELL,
DC.DC_E_RAN_UCELL_RAW
WHERE
(DC.DC_E_RAN_UCELL_RAW.HOUR_ID=DC.DIM_TIME.HOUR_ID and DC.DC_E_RAN_UCELL_RAW.MIN_ID=DC.DIM_TIME.MIN_ID)
AND (DC.DC_E_RAN_UCELL_RAW.DATE_ID=DC.DIM_DATE.DATE_ID)
AND (DC.DC_E_RAN_UCELL_RAW.OSS_ID=DC.DIM_E_RAN_UCELL.OSS_ID)
AND (DC.DC_E_RAN_UCELL_RAW.RNC=DC.DIM_E_RAN_UCELL.RNC_ID)
AND (DC.DC_E_RAN_UCELL_RAW.UtranCell=DC.DIM_E_RAN_UCELL.UCELL_ID)
AND
(
DC.DIM_DATE.DATE_ID IN ('2017-08-14')
AND
DC.DIM_E_RAN_UCELL.RBS_ID IN ('DN1U0441')
)
GROUP BY
DC.DIM_DATE.DATE_ID,
DC.DIM_E_RAN_UCELL.RBS_ID
The problem is with the last row of the SELECT statement, without it the result is this:
DATE_ID RBS_ID 3G_DATA_ERLANG 3G_SPEECH_ERLANG
8/14/2017 DN1U0441 421.8541 33.5055
When is included I got this error:
Lookup Error - Sybase Database Error: Invalid data conversion
Any Help? Is Sybase ASE DataBase

Related

Does JOIN works with LIMIT and OFFSET along WHERE clause

I'm working on spring boot project where I am trying to run following query on both sql client and spring boot code.
SELECT two.STORE_NBR, two.TLE_WORK_ORDER_ID,
tj.SERVICE_START_TS, tj.SERVICE_END_TS, tj.WIN_NBR
FROM TLE_WORK_ORDER AS two
INNER JOIN TLE_TECHNICIAN_JOB AS tj
ON ((two.TLE_WORK_ORDER_ID = tj.TLE_WORK_ORDER_ID))
WHERE CREATION_TIMESTAMP LIKE '%2017-11-13%'
LIMIT 5 OFFSET 2;
The data type of CREATION_TIMESTAMP is string.
This query is throwing an error.
Can someone explain that what is the issue with this query?
The query is throwing following error:
org.jkiss.dbeaver.model.sql.DBSQLException: SQL Error [102] [S0001]: Incorrect syntax near 'LIMIT'.
at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.executeStatement(JDBCStatementImpl.java:133)
at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.executeStatement(SQLQueryJob.java:577)
at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.lambda$1(SQLQueryJob.java:486)
at org.jkiss.dbeaver.model.exec.DBExecUtils.tryExecuteRecover(DBExecUtils.java:172)
at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.executeSingleQuery(SQLQueryJob.java:493)
at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.extractData(SQLQueryJob.java:894)
at org.jkiss.dbeaver.ui.editors.sql.SQLEditor$QueryResultsContainer.readData(SQLEditor.java:3710)
at org.jkiss.dbeaver.ui.controls.resultset.ResultSetJobDataRead.lambda$0(ResultSetJobDataRead.java:123)
at org.jkiss.dbeaver.model.exec.DBExecUtils.tryExecuteRecover(DBExecUtils.java:172)
at org.jkiss.dbeaver.ui.controls.resultset.ResultSetJobDataRead.run(ResultSetJobDataRead.java:121)
at org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer$ResultSetDataPumpJob.run(ResultSetViewer.java:4949)
at org.jkiss.dbeaver.model.runtime.AbstractJob.run(AbstractJob.java:105)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'LIMIT'.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:262)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1632)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:872)
at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:767)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7418)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:3274)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:247)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:222)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.execute(SQLServerStatement.java:743)
at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.execute(JDBCStatementImpl.java:329)
at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.lambda$0(JDBCStatementImpl.java:131)
at org.jkiss.dbeaver.utils.SecurityManagerUtils.wrapDriverActions(SecurityManagerUtils.java:96)
at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.executeStatement(JDBCStatementImpl.java:131)
... 12 more
Since you're using SQL-Server, you can't use LIMIT <N> OFFSET <M> notation. You should rather use OFFSET FETCH, that uses the ORDER BY clause to determine the order of the rows, before truncating your result set.
In your specific query, you seem to be using "tj.SERVICE_START_TS", "tj.SERVICE_END_TS" as two timestamp fields, to be used in the ORDER BY clause.
Your final query should look like:
SELECT two.STORE_NBR, two.TLE_WORK_ORDER_ID,
tj.SERVICE_START_TS, tj.SERVICE_END_TS, tj.WIN_NBR
FROM TLE_WORK_ORDER AS two
INNER JOIN TLE_TECHNICIAN_JOB AS tj
ON ((two.TLE_WORK_ORDER_ID = tj.TLE_WORK_ORDER_ID))
WHERE CREATION_TIMESTAMP LIKE '%2017-11-13%'
ORDER BY tj.SERVICE_START_TS, tj.SERVICE_END_TS
OFFSET 2 ROWS
FETCH NEXT 5 ROWS ONLY;
Recommendation: It's a bad habit to use VARCHAR datatypes for date fields, in place of the DATE, DATETIME or TIMESTAMP fields. SQL-Server operates faster and gives you tool to deal with dates.

Invalid timeline function when using derivative function in TDengine

I'm executing a derivative function in TDengine database, and it reports an error.
My sql statement is:
select derivative(errors, 1s, 1) as errors from (select sum(errors) as errors from log.dnodes_info where ts>="2022-12-06 14:08:42" and ts < "2022-12-06 15:00:00" interval(1s));
The error information is:
DB error: Invalid timeline function (0.002248s)
If I execute the following sql directly, it is ok.
select sum(errors) as errors from log.dnodes_info where ts>="2022-12-06 14:08:42" and ts < "2022-12-06 15:00:00" interval(1s) limit 10;
error information
Do I use it in a wrong way?

Select on field Date in OpenEdge

I am trying to make a select on the field 'Date' in the table UVT_DatesOfVersionsBOPos using the Microsoft SQL Server Management Studio (select * from openquery ([PROALPHA], 'select Date from PAVAR.PUB.UVT_DatesOfVersionsBOPos')
Unfortunately I get the following error message:
The OLE DB provider "MSDASQL" for the connection server "PROALPHA" has the message "[DataDirect] [ODBC Progress OpenEdge Wire Protocol driver] [OPENEDGE] Syntax error in SQL statement at or about" Date from PAVAR.PUB.UVT_DatesOfVersionsB "( 10713) ".
Msg 7321, Level 16, State 2, Line 1
Failed to prepare the select date from PAVAR.PUB.UVT_DatesOfVersionsBOPos query to run for the OLE DB provider "MSDASQL" for the linked server "PROALPHA".
I assume that SQL interprets the Date field as the Date function and therefore displays an error.
Does anyone of you know the correct syntax so I can get the field?
The syntax error is because of the fact that DATE is a reserved word in OpenEdge SQL. You can use keywords as identifiers in SQL statements only if you delimit them with double quotation marks.
Example 1: This generates syntax error as you described
SQLExplorer>select date from pub.cust1;
=== SQL Exception 1 ===
SQLState=HY000
ErrorCode=-210056
[DataDirect][OpenEdge JDBC Driver][OpenEdge] Syntax error in SQL statement at or about "date from pub.cust1" (10713)
Example 2: This works as we delimit reserved word with double quotes
SQLExplorer>select "date" from pub.cust1;
date
----------
Link to the documentation: https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dmsrf/openedge-sql-reserved-words.html

Laravel - SQLSTATE[42000] - UNION

I am making a UNION between these two queries:
$first =
DB::table('pedido')
->select(DB::raw('date(fecha_pago) as fecha'),DB::raw('sum(subtotal) as ingreso'),DB::raw('0 as egreso'))
->where('idestado','=','2')
->groupBy(DB::raw('date(fecha_pago)'));
$second =
DB::table('egreso')
->select(DB::raw('date(fecha) as fecha'),DB::raw('0 as ingreso'),DB::raw('sum(monto) as egreso'))
->groupBy(DB::raw('date(fecha)'));
$final_query=
DB::select(DB::raw('date(fecha),sum(ingreso) as ingreso,sum(egreso) as egreso'))
->union($first)->union($second)
->groupBy(DB::raw('date(fecha)'))
->get();
I get the error:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'date(fecha),sum(ingreso) as ingreso,sum(egreso) as egreso' at line 1 (SQL: date(fecha),sum(ingreso) as ingreso,sum(egreso) as egreso)
DB::select() executes a raw query, unlike DB::table()->select() which is used to define fields for the query builder to select.
You're missing the DB::table() in your final query, without it, you won't be using the query builder and you'll actually be running a query of just date(fecha),sum(ingreso) as ingreso,sum(egreso) as egreso.
https://laravel.com/docs/5.6/queries#selects

Advantage Database 8.1 SQL IN clause

Using Advantage Database Server 8.1 I am having trouble executing a successful query. I am trying to do the following
SELECT * FROM Persons
WHERE LastName IN ('Hansen','Pettersen')
To check for multiple values in a column. But I get an error when I try to execute this query in Advantage.
Edit - Error
poQuery: Error 7200: AQE Error: State = 42000; NativeError = 2115; [iAnywhere Solutions][Advantage SQL Engine]Expected lexical element not found: ( There was a problem parsing the
WHERE clause in your SELECT statement. -- Location of error in the SQL statement is: 46
And here is the SQL i'm executing
select * from "Pat Visit" where
DIAG1 IN = ('43644', '43645', '43770', '43771', '43772', '43773', '43774',
'43842', '43843', '43845', '43846', '43847', '43848', '97804', '98961',
'98962', '99078')
Done
Does anyone have any Idea how I could do something similar in advantage that would be efficient as well?
Thanks
You have an extraneous = in the statement after the IN. It should be:
select * from "Pat Visit" where
DIAG1 IN ('43644', '43645', <snip> )