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 3999598
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:40:40+00:00 2026-05-20T07:40:40+00:00

I have this query : set IDENTITY_INSERT dbo.OtherData1 ON INSERT INTO OtherData1 (OtherDataID, EmployeeID,

  • 0

I have this query :

set IDENTITY_INSERT dbo.OtherData1 ON


INSERT INTO OtherData1 (OtherDataID, EmployeeID, OtherDate, OType, OSubject, StatementNo, StatementDate, Info, OtherAs, FolderSerial)

    SELECT OtherDataID, EmployeeID, 
                 CONVERT(DATE, OtherDate, 103), 
                     OType, OSubject, StatementNo, 
                     CONVERT(DATE, StatementDate), Info,
                     CASE OtherAs
           WHEN  'f' THEN 1
              WHEN  's' THEN 2
              WHEN 't' THEN 3
              WHEN 'f' THEN 4
              WHEN 'p' THEN 5
              WHEN 'o' THEN 6
           ELSE NULL END
           , FolderSerial
    FROM OtherData

I when I execute it I get this error :

Msg 241, Level 16, State 1, Line 5
Conversion failed when converting date and/or time from character string.

the values for StatementDate, OtherDate are in this format "31/1/1994" as string before convert

What is the problem?

EDIT:

if I added this line of code :

CASE WHEN ISDATE(OtherDate) = 1 THEN 
  CONVERT(DATE, OtherDate, 103)
ELSE NULL END

I tried it and it’s not working, I need some thing like it to check if vaild do the convert if not insert NULL value and I get the same error message

  • 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-05-20T07:40:41+00:00Added an answer on May 20, 2026 at 7:40 am

    ISDATE won’t work since you cannot even specify a date format as you can with CONVERT. The following is a VERY elaborate test to reformat valid dates into YYYYMMDD for which ISDATE works predictably.

    with otherdata(StatementDate) as (
    select convert(varchar(10),'1/10/2011') union all
    select '28/2/2911' union all
    select '8/12/2011' union all
    select '13/13/2011' union all
    select '13/12/2011' union all
    select '12/13/2011' union all
    select '2/29/2011' union all
    select '29/2/2011' union all
    select '29/2/2012' union all
    select '2011-02-01' union all
    select '1/1/11' union all
    select '1/1/99' union all
    select '' union all
    select null)
    
    -- THE QUERY YOU NEED is below this line. The above virtually sets up a table
    -- without having to physically create it
    select
        statementdate,
        YYYYMMDDToTest,
        ISDate(YYYYMMDDToTest)
    from otherdata
    cross apply
           (
           select TheYear = case
           when not statementdate like '%[0-9]/%[0-9]/%[0-9][0-9]' then null
           when convert(int,replace(statementdate,'/','')) != replace(statementdate,'/','') then null
           when statementdate like '%[0-9]/%[0-9]/[0-9][0-9]' then
               case when RIGHT(statementdate,2) >=50
               then '19'+RIGHT(statementdate,2)
               else '20'+RIGHT(statementdate,2)
               end
           when statementdate like '%[0-9]/%[0-9]/[1-9][0-9][0-9][0-9]' then
               RIGHT(statementdate,4)
           end
           ) A
    cross apply
           (
           select YYYYMMDDToTest = case
           when TheYear is not null then
               TheYear
               + -- month
               right(100+SUBSTRING(statementdate, charindex('/',statementdate) +1,
               charindex('/',statementdate,charindex('/',statementdate)+1)-
               charindex('/',statementdate)-1),2)
               + -- day
               right(100+LEFT(statementdate, charindex('/', StatementDate) -1),2)
           end
           ) B
    WHERE ISDate(YYYYMMDDToTest) = 0
    

    Comment out the last line WHERE ISDate(YYYYMMDDToTest) = 0 to see what it does with each date.


    EDIT

    You can turn this into a function that replaces the ISDATE – but for the SPECIFIC format [d]d/[m]m/yyyy.

    create function dbo.superIs103Date(@any varchar(50))
    returns bit as begin
    declare @theyear varchar(10)
    set @TheYear = case
           when not @any like '%[0-9]/%[0-9]/%[0-9][0-9]' then null
           when convert(int,replace(@any,'/','')) != replace(@any,'/','') then null
           when @any like '%[0-9]/%[0-9]/[0-9][0-9]' then
               case when RIGHT(@any,2) >=50
               then '19'+RIGHT(@any,2)
               else '20'+RIGHT(@any,2)
               end
           when @any like '%[0-9]/%[0-9]/[1-9][0-9][0-9][0-9]' then
               RIGHT(@any,4)
           end
    declare @YYYYMMDDToTest varchar(50)
    set @YYYYMMDDToTest = case
           when @TheYear is not null then
               @TheYear
               + -- month
               right(100+SUBSTRING(@any, charindex('/',@any) +1,
               charindex('/',@any,charindex('/',@any)+1)-
               charindex('/',@any)-1),2)
               + -- day
               right(100+LEFT(@any, charindex('/', @any) -1),2)
           end
    return ISDate(@YYYYMMDDToTest)
    end
    GO
    
    -- example usage
    select dbo.superIs103Date('33/1/1700')
    -- returns 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to do this query INSERT INTO dbo.tbl_A_archive SELECT * FROM SERVER0031.DB.dbo.tbl_A but
I have an insert query that gets generated like this INSERT INTO InvoiceDetail (LegacyId,InvoiceId,DetailTypeId,Fee,FeeTax,Investigatorid,SalespersonId,CreateDate,CreatedById,IsChargeBack,Expense,RepoAgentId,PayeeName,ExpensePaymentId,AdjustDetailId)
I have this query in sql server 2000: select pwdencrypt('AAAA') which outputs an encrypted
I have this query statement and want to only get records that has a
I have this query in LINQ to Entities. var query = (from s in
I have this query: SELECT page.id, revision.title, revision.number FROM page INNER JOIN revision ON
I have this SQL query: SELECT * FROM IMAGES WHERE IMAGENAME in ('IMG1', 'IMG2',
I have this method in my db class public function query($queryString) { if (!$this->_connected)
This query is related to this one I asked yesterday. I have a radio
i have this in my BlogRepository public IQueryable<Subnus.MVC.Data.Model.Post> GetPosts() { var query = from

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.