Solved

Choosing a higher date if two date fields are present

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

679 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