Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9087261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:39:55+00:00 2026-06-16T21:39:55+00:00

I have a table: Comments (Id int identity primary key, PersonId Int(6), Comment1 Char(60))

  • 0

I have a table:

Comments (Id int identity primary key, PersonId Int(6), Comment1 Char(60))

The field Comment1 is supposed to contain nonessential comments only, however the field has been used to store nonessential comments but also important dates in the format dd/mm/yyyy.

So for example, the data in the table appears like the following:

* Id * PersonId *    Comment1     *
|  1 |        5 | Likes Chocolate |
|  2 |        5 | 19/05/1992      |
|  3 |        5 | 23/07/1999      |
|  4 |        5 | 05/06/1994      |
|  5 |        8 | 07/12/1998      |
|  6 |        8 | Is very Tall    |
|  7 |        8 | 24/05/1995      |
|  8 |        8 | 16/10/2002      |
|  9 |       11 | 13/11/2005      |
| 10 |       11 | 21/09/2000      |
| 11 |       11 | 8/99/100/23-1   |

SQL Fiddle

They now need to find the one row for each person which contains the most recent date in the Comment1 field.

Firstly I tried to remove those rows which did not contain a valid date using the following Query:

Select 
  Id,
  PersonId,
  Case 
    When IsDate(Comment1) = 1 
    Then convert(date, cast(rtrim(Comment1) as nvarchar), 103)
    Else NULL
  End
From Comments

But this only returned me:

* Id * PersonId *    Comment1     *
|  4 |        5 | 1994-06-05      |
|  5 |        8 | 1998-12-07      |

The other rows being (null). This can be seen in the SQL Fiddle link.

Could some one please tell me where I’m going wrong?

Once this select statement returns what I require I expect I should be able to return the most recent date per PersonId using an aggregate function.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T21:39:56+00:00Added an answer on June 16, 2026 at 9:39 pm

    Use SET DATEFORMAT

    set dateformat dmy
    
    Select 
      Id,
      PersonId,
      Case 
        When IsDate(Comment1) = 1 
        Then convert(date, cast(rtrim(Comment1) as nvarchar), 103)
        Else NULL 
      End
    From Comments
    

    SQL Fiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an invoice table that has InvoiceID (int identity ) Primary key. and
I have two tables: CREATE TABLE InmarsatZenith.dbo.ClientJob (JobRef int PRIMARY KEY NOT NULL, IntRef
Say I have the following table: Create Table Comments ( ID Int Identity(1,1) Not
I have large table. consisting of only 3 columns (id(INT),bookmarkID(INT),tagID(INT)).I have two BTREE indexes
i have comments table in sql server structured as CREATE TABLE [dbo].[LS_Commentes]( [CommentId] [int]
I have a table called PurchaseOrderDetail. TABLE PurchaseOrderDetail PurchaseOrderDetail int, Comments nvarchar(500) In the
I have two tables: CREATE TABLE IF NOT EXISTS `comments` ( `id` int(11) NOT
Given this table: CREATE TABLE [Comments] ( [Id] [int] IDENTITY(1, 1) NOT NULL, [Text]
I have a table (session_comments) with the following fields structure: student_id (foreign key to
I have this mysql table called comments which looks like this: commentID parentID type

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.