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.
jknj72Asked:
Who is Participating?
 
sdstuberCommented:
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
 
jknj72Author Commented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
same expression:

select nvl(start_date, create_date) sorted_date
  from yourtable ...
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
jknj72Author Commented:
that should do it. Thanks for your help
0
 
jknj72Author Commented:
thanks
0
 
sdstuberCommented:
isn't a split in order?  the accepted post simply restates the same expression originally posted
0
 
awking00Commented:
FWIW, could also have used coalesce(start_date, create_date) sorted_date.
0
 
jknj72Author Commented:
thanks
0
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.