Select on field Date in OpenEdge - sql

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

Related

I want to read data out by linked server in SSMS

Msg 7356, Level 16, State 1, Line 1
The OLE DB provider "MSDASQL" for linked server "" supplied inconsistent metadata for a column. The column "" (compile-time ordinal 11) of object "" was reported to have a "DBCOLUMNFLAGS_ISLONG" of 128 at compile time and 0 at run time.
And O also got these message when I just want read out a single column and not that one which has some problem.
I try to use SELECT * from .... reading form and
SELECT * FROM OPENQUERY([], '') also.

Microsoft ODBC Query for excluding a specific value from the column

I converted an Excel Workbook into a database using ODBC Data Sources.
Used the Run Query Activity in UiPath under the Database Activities and tried to extract data from the Excel in a particular column excluding a specific value in this case it is zero.
Below is the query I tried to use but it returns the
"SELECT * FROM [Export Worksheet$] WHERE NOT CStr(INT_RECV_CLOSING_BAL)= '0';"
Am getting an error of:
Run query: ERROR [42000] [Microsoft][ODBC Excel Driver] Syntax error in string in query expression
The syntax should be where column name meets requirement or you can use IN(value) or NOT IN(value)
Try using the below to see if they work:
SELECT *
FROM [Export Worksheet$]
WHERE CStr(INT_RECV_CLOSING_BAL) != '0';
SELECT *
FROM [Export Worksheet$]
WHERE CStr(INT_RECV_CLOSING_BAL) <> '0';

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

Facing issue while running select query on DB2

I'm querying a DB2 table (STG_TOOL) with 2 columns - T_L_ID - Integer, Name - VARCHAR(20).
SELECT T_L_ID, Name FROM STG_TOOL;
The query returns answer. However, the below query gives error.
SELECT T_L_ID, RTRIM(Name) FROM STG_TOOL;
This query gives error at 78th row.
DB2 Database Error: ERROR [42815] [IBM][DB2] SQL0171N The data type,
length or value of the argument for the parameter in position "1" of
routine "SYSIBM.RTRIM" is incorrect. Parameter name: "". 1 0
The reason identified is that Name in 78th row has a replacement character - '�'.
Even, the same query with a where clause gives us the error.
SELECT T_L_ID, RTRIM(Name) FROM STG_TOOL WHERE T_L_ID = 78;
The sample date on 78th rows is T_L_ID = 1040 & Name = 'test�'
The above mentioned error re-occurs for the above query.
What does the error implies? How can this be handled/solved?
Adding details to the post:
Version: DSN11010 (version 11)
OS: z/OS
Encoding: Unicode
Toad for DB2 is being used for querying. Toad version - 5.5

Sybase Database Error: Invalid data conversion

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