January 14, 2016 at 3:56 am
Hi all,
I have some code that works in Access but now I want to forward the code to our IT department to make a view in our SQL database.
Could anyone please help me convert it so it is correct for Oracle SQL and not Access SQL if that makes sense?
Thanks in advance
Chris
SELECT T1.*, (SELECT TOP 1 T3.[SMN_DATEC]-1 FROM
(SELECT T2.[DET_NUMBERA], T2.[SMN_DATEC] FROM [CHRISCS_EMSAL] AS T2 ORDER BY [DET_NUMBERA],[SMN_DATEC]) AS T3 WHERE T3.[DET_NUMBERA] = T1.[DET_NUMBERA] AND T3.[SMN_DATEC] > T1.[SMN_DATEC] ) AS EndDate, T1.[DET_NUMBERA], T1.[SMN_DATEC]
FROM CHRISCS_EMSAL AS T1
ORDER BY T1.[DET_NUMBERA], T1.[SMN_DATEC];
I have tried to test it in ORACLE SQL Developer but am getting the error:
Error at line 1, column 25:
ORA-00923: FROM keyword not found where expected
January 14, 2016 at 6:48 am
It appears you are using two subqueries in the expression, and Access does subqueries somewhat differently than ANSI SQL, which is closer to Oracle. Some versions of Access let you use ANSI SQL, or something close to it, so you might try changing that option in Access and see what it does. Unfortunately I am not conversant with Oracle, so hopefully someone else with that expertise can make further suggestions.
Wendell
Colorful Colorado
You can't see the view if you don't climb the mountain!
January 14, 2016 at 7:38 am
Oracle does not use TOP(n). One alternative is to filter by ROW_NUMBER().
SELECT T1.*,
(SELECT END_DATE
FROM (SELECT T3.SMN_DATEC-1 AS END_DATE,
ROW_NUMBER() OVER(ORDER BY DET_NUMBERA,SMN_DATEC) AS ROWNO
FROM (SELECT T2.DET_NUMBERA,
T2.SMN_DATEC
FROM CHRISCS_EMSAL AS T2
ORDER BY DET_NUMBERA,SMN_DATEC) AS T3
WHERE T3.DET_NUMBERA = T1.DET_NUMBERA
AND T3.SMN_DATEC > T1.SMN_DATEC ) T4
WHERE ROWNO = 1) AS EndDate,
T1.DET_NUMBERA, T1.SMN_DATEC
FROM CHRISCS_EMSAL AS T1
ORDER BY T1.DET_NUMBERA, T1.SMN_DATEC;
This code is untested because I don't have an Oracle server nor DDL and sample data.
January 14, 2016 at 7:58 am
Luis Cazares (1/14/2016)
Oracle does not use TOP(n). One alternative is to filter by ROW_NUMBER().
SELECT T1.*,
(SELECT END_DATE
FROM (SELECT T3.SMN_DATEC-1 AS END_DATE,
ROW_NUMBER() OVER(ORDER BY DET_NUMBERA,SMN_DATEC) AS ROWNO
FROM (SELECT T2.DET_NUMBERA,
T2.SMN_DATEC
FROM CHRISCS_EMSAL AS T2
ORDER BY DET_NUMBERA,SMN_DATEC) AS T3
WHERE T3.DET_NUMBERA = T1.DET_NUMBERA
AND T3.SMN_DATEC > T1.SMN_DATEC ) T4
WHERE ROWNO = 1) AS EndDate,
T1.DET_NUMBERA, T1.SMN_DATEC
FROM CHRISCS_EMSAL AS T1
ORDER BY T1.DET_NUMBERA, T1.SMN_DATEC;
This code is untested because I don't have an Oracle server nor DDL and sample data.
Hi Luis,
Many thanks for your reply, I am getting the following error:
Error at line 7, column 38:
ORA-00907: missing right parenthesis
Thanks again.
January 14, 2016 at 8:04 am
wrightyrx7 (1/14/2016)
Luis Cazares (1/14/2016)
Oracle does not use TOP(n). One alternative is to filter by ROW_NUMBER().
SELECT T1.*,
(SELECT END_DATE
FROM (SELECT T3.SMN_DATEC-1 AS END_DATE,
ROW_NUMBER() OVER(ORDER BY DET_NUMBERA,SMN_DATEC) AS ROWNO
FROM (SELECT T2.DET_NUMBERA,
T2.SMN_DATEC
FROM CHRISCS_EMSAL AS T2
ORDER BY DET_NUMBERA,SMN_DATEC) AS T3
WHERE T3.DET_NUMBERA = T1.DET_NUMBERA
AND T3.SMN_DATEC > T1.SMN_DATEC ) T4
WHERE ROWNO = 1) AS EndDate,
T1.DET_NUMBERA, T1.SMN_DATEC
FROM CHRISCS_EMSAL AS T1
ORDER BY T1.DET_NUMBERA, T1.SMN_DATEC;
This code is untested because I don't have an Oracle server nor DDL and sample data.
Hi Luis,
Many thanks for your reply, I am getting the following error:
Error at line 7, column 38:
ORA-00907: missing right parenthesis
Thanks again.
Are you using exactly that code by itself? I can't find any missing parenthesis.
January 14, 2016 at 8:10 am
Luis Cazares (1/14/2016)
wrightyrx7 (1/14/2016)
Luis Cazares (1/14/2016)
Oracle does not use TOP(n). One alternative is to filter by ROW_NUMBER().
SELECT T1.*,
(SELECT END_DATE
FROM (SELECT T3.SMN_DATEC-1 AS END_DATE,
ROW_NUMBER() OVER(ORDER BY DET_NUMBERA,SMN_DATEC) AS ROWNO
FROM (SELECT T2.DET_NUMBERA,
T2.SMN_DATEC
FROM CHRISCS_EMSAL AS T2
ORDER BY DET_NUMBERA,SMN_DATEC) AS T3
WHERE T3.DET_NUMBERA = T1.DET_NUMBERA
AND T3.SMN_DATEC > T1.SMN_DATEC ) T4
WHERE ROWNO = 1) AS EndDate,
T1.DET_NUMBERA, T1.SMN_DATEC
FROM CHRISCS_EMSAL AS T1
ORDER BY T1.DET_NUMBERA, T1.SMN_DATEC;
This code is untested because I don't have an Oracle server nor DDL and sample data.
Hi Luis,
Many thanks for your reply, I am getting the following error:
Error at line 7, column 38:
ORA-00907: missing right parenthesis
Thanks again.
Are you using exactly that code by itself? I can't find any missing parenthesis.
Yes your code only :/
when the error appears it points to the letter "A" in the word "AS" in the following line
FROM CHRISCS_EMSAL AS T2
January 14, 2016 at 8:52 am
I'm not sure what's the problem. The code should be working and there's no missing parenthesis. That's just another reason why I hate Oracle.
Maybe someone else can help.
By the way, the code works in SQL Server, and should work with most RDBMS as everything is under the SQL standard.
January 14, 2016 at 9:04 am
Luis Cazares (1/14/2016)
I'm not sure what's the problem. The code should be working and there's no missing parenthesis. That's just another reason why I hate Oracle.Maybe someone else can help.
By the way, the code works in SQL Server, and should work with most RDBMS as everything is under the SQL standard.
It must be something on my side then, I really appreciate you spending the time writing the code for me.
Thanks again
Chris
January 14, 2016 at 9:07 am
wrightyrx7 (1/14/2016)
Luis Cazares (1/14/2016)
I'm not sure what's the problem. The code should be working and there's no missing parenthesis. That's just another reason why I hate Oracle.Maybe someone else can help.
By the way, the code works in SQL Server, and should work with most RDBMS as everything is under the SQL standard.
It must be something on my side then, I really appreciate you spending the time writing the code for me.
Thanks again
Chris
It's basically on the Oracle side, but I haven't used Oracle recently to be sure what it is. Try an Oracle forum for more help.
January 14, 2016 at 9:07 am
I think LEAD has been in Oracle for sometime.
Something like:
SELECT *
,LEAD(SMN_DATEC, 1) OVER (PARTITION BY DET_NUMBERA ORDER BY SMN_DATEC) - 1 AS EndDate
FROM CHRISCS_EMSAL
ORDER BY DET_NUMBERA, SMN_DATEC;
June 10, 2016 at 7:09 am
This was removed by the editor as SPAM
March 11, 2017 at 11:54 am
This was removed by the editor as SPAM
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply