Solved

Choosing a higher date if two date fields are present

Posted on 2006-06-29
5
446 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
  • 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 250 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

762 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

24 Experts available now in Live!

Get 1:1 Help Now