?
Solved

Choosing a higher date if two date fields are present

Posted on 2006-06-29
5
Medium Priority
?
455 Views
Last Modified: 2008-02-01
Ok this is probably easy but I do not know the SQL syntax.

SELECT ENTERED, REENTERED FROM MYTABLE

Let us say this is our table, and both are date fields. The left field (ENTERED) is always present, but when (REENTERED) is present I want the date to be used if it is newer and I am pretty sure it will always be newer.  I only need one field returned though, not both.
0
Comment
Question by:ParanoidOne
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 28

Expert Comment

by:rafrancisco
ID: 17012520
You can do it this way:

SELECT ISNULL(REENTERED, ENTERED) as Entered FROM MYTABLE
0
 
LVL 28

Accepted Solution

by:
rafrancisco earned 1000 total points
ID: 17012527
Here's another way to do it:

SELECT CASE WHEN REENTERED IS NOT NULL AND REENTERED > ENTERED
                    THEN REENTERED ELSE ENTERED END AS ENTERED
FROM MYTABLE
0
 

Author Comment

by:ParanoidOne
ID: 17012814
Rafrancisco your first only seemed to return the REENTERED date. The secod statement worked fine.

I am getting some concurrency errors in VB.NET when trying to update that field, is there a way to update or should I just close not to update that particular field.
0
 
LVL 28

Expert Comment

by:rafrancisco
ID: 17012832
Might as well not update the particular field so that you have a history of values in your table.
0
 

Author Comment

by:ParanoidOne
ID: 17013622
Yeah I do not think I will.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

719 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