Solved

Oracle syntax

Posted on 2013-02-04
9
270 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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 32

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
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 video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

911 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

17 Experts available now in Live!

Get 1:1 Help Now