Solved

Oracle syntax

Posted on 2013-02-04
9
269 Views
Last Modified: 2013-02-07
I have a query that has 2 dates(start and end date) and if it does not have a value, then its considered a blank, and I want to sort by another date(create date) but if the date has a value I want it sorted by start date. In other words I want the blanks to use create date and if it has a value sort by the start date but I want them all in one sortable field

So maybe we can include an aliased field that has the logic above and I can sort a column but it would have to be a mixture of the 2 fields so if I have 3 records2 with start dates and one blank that has a create date in between the 2 start dates I want them coming back with the blank as the middle date from the sort....

Hope this makes sense.
0
Comment
Question by:jknj72
9 Comments
 
LVL 73

Accepted Solution

by:
sdstuber earned 250 total points
ID: 38851045
select * from your_table
order by nvl(start_date, create_date)


if that doesn't do it, please provide sample data an expected output
0
 

Author Comment

by:jknj72
ID: 38851066
I think that will work how can I get that into one aliased field in my select statement?

logic
if start_date = '' then
     create_date
else
  start_date
end if as 'SORTED DATE'

What would be the syntax for this?
0
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 total points
ID: 38851073
same expression:

select nvl(start_date, create_date) sorted_date
  from yourtable ...
0
 

Author Comment

by:jknj72
ID: 38851092
that should do it. Thanks for your help
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:jknj72
ID: 38851098
thanks
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 38851100
isn't a split in order?  the accepted post simply restates the same expression originally posted
0
 
LVL 31

Expert Comment

by:awking00
ID: 38851672
FWIW, could also have used coalesce(start_date, create_date) sorted_date.
0
 

Author Closing Comment

by:jknj72
ID: 38865248
thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.‚Äč
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Via a live example, show how to take different types of Oracle backups using RMAN.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now