Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

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.
0
jknj72
Asked:
jknj72
2 Solutions
 
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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now