Click here to Skip to main content
15,886,807 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to get the first ten character as output from Query in Oracle 16/06/1979 12:00:00 AM
the output should be 16/06/1979 and in ascending order I got the output but was not in ascending order plz let me know the query

select empno, Substr(INCREMENTDATE, 1, 10) AS INCREMENTDATE, From sr_incr_details Where EMPNO='" + Empno + "' Order By INCREMENTDATE";
Posted
Comments
Sinisa Hajnal 5-Sep-14 2:21am    
The title is misleading, it seems as if your problem is getting the text out, instead it is about sort order.

Since this is a string Column this may not order correct assenting order as dates. if you need to get only date part from the column, you need to convert the column first as DATE TIME Column and then get the DatePart as TO_DATE('DATE', 'YYYY-MM-DD') and Call with Order By
 
Share this answer
 
Try this

C#
select empno, TO_CHAR(INCREMENTDATE, 'DD/MM/YYYY') AS UPDATEDINCRDATE, INCREMENTDATE
From sr_incr_details 
Where EMPNO=123
Order By INCREMENTDATE


and Ignore the last column.
 
Share this answer
 
Comments
Khan Sameer 5-Sep-14 2:26am    
Thnks a lot
Either change the alias so it is different from column name and then use it (with TO_DATE()) in order by clause or change order by clause to
SQL
ORDER BY TO_DATE(Substr(INCREMENTDATE, 1, 10))


If this solves your problem please accept the solution to make it easier for others to find it. Thank you.
 
Share this answer
 
v2
Comments
Khan Sameer 5-Sep-14 2:26am    
Thnks a lot

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