Solved

Choosing a higher date if two date fields are present

Posted on 2006-06-29
5
452 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 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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

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.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

752 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