Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a field BillNumber in a table where bill numbers can be repeated, and i want to get the last row of a certain bill, I used this statement which works fine on Sql Server but not on Oracle database:

Select MB.* From SADAD.MAINBILLDETAILS AS MB Inner Join (Select BILLNUMBER, Max(CREATEDON) AS LastDate From SADAD.MAINBILLDETAILS Group By BILLNUMBER) As LastBill On MB.BILLNUMBER = LastBill.BILLNUMBER AND MB.CREATEDON = LastBill.LastDate Where Not ISREJECTED Is Null And SubStr(MB.BILLNUMBER,1,3) ='301' And CREATEDON Between To_Date('2016/07/19', 'YYYY/MM/DD') And To_Date('2016/10/19', 'YYYY/MM/DD') Order By CREATEDON

Error message:
ORA-00933: Command not properly ended

What I have tried:

Select MB.* From SADAD.MAINBILLDETAILS AS MB Inner Join (Select BILLNUMBER, Max(CREATEDON) AS LastDate From SADAD.MAINBILLDETAILS Group By BILLNUMBER) As LastBill On MB.BILLNUMBER = LastBill.BILLNUMBER AND MB.CREATEDON = LastBill.LastDate Where Not ISREJECTED Is Null And SubStr(MB.BILLNUMBER,1,3) ='301' And CREATEDON Between To_Date('2016/07/19', 'YYYY/MM/DD') And To_Date('2016/10/19', 'YYYY/MM/DD') Order By CREATEDON
Posted
Comments
CHill60 14-Mar-17 12:54pm    
If this is Oracle then it needs a command delimiter at the end of the Select Statement. It's usually a semi-colon

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900