Solved

Choosing a higher date if two date fields are present

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

777 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