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