Okay I'm using PeopleSoft's Query Manager trying to write an expression. The original expression converted a date format into DD MON YY, here's the original expression that works:
CONVERT(VARCHAR(10), A.TERMINATION_DT, 103) AS [DD MON YY]
I need to add termination dates for a few people, manually (they're not termed yet, but will be, so I have to input it like this).
So I thought I could do a case statement:
(CASE WHEN B.EMPLID IN ('XXXXXX') THEN '2022-08-19' ELSE (CONVERT(VARCHAR(10), A.TERMINATION_DT, 103) AS [DD MON YY]) END)
When I input the above I get the following error:
A SQL error occurred. Please consult your system log for details.
Error in running query because of SQL Error, Code=8603,
Message=[Microsoft][ODBC Driver 13 for SQL Server][SQL
Server]Incorrect syntax near the keyword 'AS'. [Microsoft][ODBC Driver
13 for SQL Server][SQL Server]Incorrect syntax near 'PS_JOB'.
[Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Incorrect syntax
nea란ᆌŪ (50,380)
Where am I going wrong?
The problem with your edit of the query is that you put AS [DD MON YY] statement, which sets the alias for the column, into the CASE statement.
It should be after the entire CASE statement.
Provided that the rest of the syntax is correct, it should be:
(CASE
WHEN B.EMPLID IN ('XXXXXX') THEN '2022-08-19'
ELSE CONVERT(VARCHAR(10), A.TERMINATION_DT, 103)
END) AS [DD MON YY]
Okay I figured it out. Not terribly difficult in the end.
(CASE WHEN B.EMPLID IN ('XXXXXX') THEN '2022-08-19' ELSE (CONVERT(VARCHAR(10), A.TERMINATION_DT, 103) ) END)
Related
I have to create an SQR that generates a list of EEIDs, if there were any changes to the Pension data in the past day. The SQR compiles and works perfectly when I hardcode in the table names.
However, when I tried using variables for the table names, I get a compile error
I've pasted the portion of SQR that I'm trying to fix
When I start using $tableName and $auditTableName as table variables, that's when I get the error and I'm not sure what is going wrong
Can anyone help?
Please and Thank You
!***************************
begin-procedure Process-Main
!***************************
let $tableName = 'PS_PENSION_PLAN'
let $auditTableName = 'PS_AUDIT_PENSION_PLN'
let $dummy-dyn-variable = ''
begin-SELECT DISTINCT
L.EMPLID
L.EMPL_RCD
do someProcName(&L.EMPLID, &L.EMPL_RCD)
FROM [$dummy-dyn-variable]
(
SELECT DISTINCT
PP.EMPLID,
PP.EMPL_RCD,
PP.EFFDT,
'1901-01-01 12:00:00' AS AUDIT_STAMP
FROM [$dummy-dyn-variable] [$tableName] PP
UNION
SELECT DISTINCT
A.EMPLID,
A.EMPL_RCD,
A.EFFDT,
A.AUDIT_STAMP
FROM [$dummy-dyn-variable] [$auditTableName] A
)L
WHERE DATEDIFF(DAY,CAST(L.AUDIT_STAMP AS DATE),SYSDATE) = 1
ORDER BY 1,2
end-SELECT
end-procedure
Edit:
does the UNION have anything to do with this?
I keep receiving is this error:
(SQR 5528) ODBC SQL dbdesc: SQLNumResultCols error 102 in cursor 1:
[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'FROM'.
(SQR 5528) ODBC SQL dbdesc: SQLNumResultCols error 8180 in cursor 1:
[Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared.
Edit2:
Ok, initial problem solved with [$dummy-dyn-variable], which led to the next problem with the DO command. I've updated the code above with DO someProcName(param_a, param_b)
I am now getting an error saying:
(SQR 2002) DO arguments do not match procedure's
Weird part, if I remove the dynamic table variables and hardcode the table names in the FROM section, then it compiles properly without errors. This makes me believe that the error is not related to my someProcName (maybe?)
am I missing something here?
I am trying to run the below bteq script in unix.
BTEQ -- Update.txt
.LOGON i.p/username,password
.set width 132
.set errorout stdout
sel date, time;
.set maxerror 1
Nonsequenced validtime
update SCHEMA_1.TABLE_1
set ef_dtm = period( timestamp '1900-01-01 00:00:00.999999',
end(ef_dtm))
where begin(ef_dtm) > CURRENT_TIMESTAMP
and end(ef_dtm) = to_date('12/31/9999', 'mm/dd/yyyy')
.quit
But i am getting the below error
*** Failure 3706 Syntax error: Invalid use of JSON entity reference syntax on non-JSON type.
Statement# 1, Info =0
Exiting BTEQ... RC (return code) = 8
Please note that if I run the update statement along with nonsequenced
valid time directly in SQL Assistant, it works without any issue.
Can you please help me fix this?
Let me know if you need any more info.
User semicolon at the end of update statement.
Why the following query fails on Oracle 10 an not on Oracle 11.
SELECT trunc(DBMS_RANDOM.value(low => 10, high =>50)) from dual;
Oracle 10:
ORA-00907: missing right parenthesis
This answer is a bit speculative, but one possible explanation for the missing right parentheses error is that this error is not really about missing parentheses. Instead, if the API for DBMS_RANDOM.value is different in your version of Oracle 10 vs. Oracle 11 then you could be seeing this error. Try this query instead:
SELECT TRUNC(DBMS_RANDOM.value(10, 50))
FROM dual
If this works, then you will know that the API has changed between Oracle 10 and 11.
Here is a reference which uses the API as I have in my query.
This was a new feature in 11gR1:
Beginning in this release, it is now possible to invoke the function
in a SQL statement. For example, named notation syntax is:
SELECT f(pn=>3, p2=>2, p1=>1) FROM dual
Or, mixed notation is:
SELECT f(1, pn=>3) FROM dual
In previous releases, attempting named or mixed notation resulted in
an error.
So prior to 11g you could only call a PL/SQL function from SQL using positional notation, e.g.
SELECT trunc(DBMS_RANDOM.value(10, 50)) from dual;
... as #TimBiegeleisen has already shown works. The 'missing right parenthesis' error doesn't necessarily mean your parentheses are unbalanced; just that the parser saw something it didn't expect where it thought a parenthesis might go - in this case, at the =>.
I submitted a simple (so I thought) query via RODBC :
ch <- odbcConnect(dsn.name, believeNRows=FALSE, rows_at_time=1)
sqlQuery(ch, "CURRENT_TIMESTAMP()")
And it threw the following error:
[1] "42000? -1 Malformed SQL Statement: Unrecognized keyword: CURRENT_TIMESTAMP\r\nStatement:CURRENT_TIMESTAMP()"
[2] "[RODBC] ERROR: Could not SQLExecDirect 'CURRENT_TIMESTAMP()'"
I thought CURRENT_TIMESTAMP() is a common SQL command and didn't expect this to not run. I had checked that the ODBC connection (RSSBus DynamicsCRM Source x64) supports CURRENT_TIMESTAMP(). My connection is OK, I was able to perform some other SQL queries.
So is there a problem with my syntax above? Or is there a list of keywords that RODBC doesn't recognise?
In the above code, first line i.e.
ch <- odbcConnect(dsn.name, believeNRows=FALSE, rows_at_time=1)
creates a connection to your ODBC data source name (dsn.name). So here ch basically stores the connection instance. The second line:
sqlQuery(ch, "CURRENT_TIMESTAMP()")
executes the SQL query on the connection i.e. ch and returns the result in a data frame. So instead of using the method CURRENT_TIMESTAMP() use complete query:
sqlQuery(ch, "SELECT CURRENT_TIMESTAMP()")
I hope this will help.
I have been trying to solve the issue to group by datetime for sometimes but I still can't resolve it.
Please give some advice on what wrong with my syntax?
Sytnax error message i get:-
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_FORMAT(mdatetime,'%Y-%m-%d') AS 'Date',count(*) AS 'Total Registrants' fro' at line 1
select $regdate AS 'Date',count(*) AS 'Total Registrants' from $regTable where $regdate <= '$date' group by $regdate order by $regdate DESC LIMIT 10