Oracle syntax

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.
Who is Participating?
sdstuberConnect With a Mentor Commented:
select * from your_table
order by nvl(start_date, create_date)

if that doesn't do it, please provide sample data an expected output
jknj72Author Commented:
I think that will work how can I get that into one aliased field in my select statement?

if start_date = '' then
end if as 'SORTED DATE'

What would be the syntax for this?
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
same expression:

select nvl(start_date, create_date) sorted_date
  from yourtable ...
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

jknj72Author Commented:
that should do it. Thanks for your help
jknj72Author Commented:
isn't a split in order?  the accepted post simply restates the same expression originally posted
FWIW, could also have used coalesce(start_date, create_date) sorted_date.
jknj72Author Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.