Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Multiple Date Sorting

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-02-27 : 12:03:09
Jeff writes "One of our Accounting tables contains multiple columns for dates of submittals i.e. first second, third. They want a query that will show all the projects sorted by projects with the next upcoming date from any one of the three submittal columns. Is this even possible?"

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2006-02-27 : 12:27:48
Look up CASE in Books Online..
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-02-27 : 13:19:20
Hi Jeff, Welcome to SQL Team!

Something like this perhaps?

SELECT CASE WHEN SubmittalColumn1 > GetDate()
AND (SubmittalColumn1 < SubmittalColumn2 OR SubmittalColumn2 IS NULL)
AND (SubmittalColumn1 < SubmittalColumn3 OR SubmittalColumn3 IS NULL)
THEN SubmittalColumn1
WHEN SubmittalColumn2 > GetDate()
AND (SubmittalColumn2 < SubmittalColumn3 OR SubmittalColumn3 IS NULL)
THEN SubmittalColumn2
ELSE SubmittalColumn3
FROM MyAccountingTable
ORDER BY MyProjectCodeColumn

Kristen
Go to Top of Page
   

- Advertisement -