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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:54:34+00:00 2026-06-12T21:54:34+00:00

Why does this statement succeed? SELECT CAST(’08:50′ as time) But this one fails? tmrec

  • 0

Why does this statement succeed?

    SELECT CAST('08:50' as time)

But this one fails? tmrec is an nvarchar(6) column and contains the same value '08:50'. This is making me crazy since last 1 hour.

    SELECT   TOP 1 CAST(tmrec as time) 
    FROM     Instr 
    WHERE    igrp = 'JD' 
    ORDER BY ino , smallin

This screenshot shows the 1st query’s result. It contains 08:50. Yet the 2nd query throws error.

Edit:

Even this doesn’t work which guarantees that conversion is applied only on fetched records:

    SELECT CAST( tmrec as time)
    FROM
         (
            SELECT TOP 1 tmrec
            FROM   [ccwise-courts].[dbo].[INSTR]
            WHERE  igrp = 'JD' 
            ORDER BY ino , smallin
         ) v
  • 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-12T21:54:35+00:00Added an answer on June 12, 2026 at 9:54 pm

    Generally, to look for bad data, you can use a query like this:

    SELECT TOP(100) '-->' + REPLACE(tmrec, ' ', '*') + '<--bad'
    FROM Instr
    WHERE ISDATE(tmrec) = 0
    

    And if you still cannot make it out, you can list out the specific ASCII code of the characters involved (here I go up to 6 per the question):

    SELECT TOP(100) '-->' + REPLACE(tmrec, ' ', '*') + '<--bad',
      Char1 = ascii(substring(tmrec,1,1)),
      Char2 = ascii(substring(tmrec,2,1)),
      Char3 = ascii(substring(tmrec,3,1)),
      Char4 = ascii(substring(tmrec,4,1)),
      Char5 = ascii(substring(tmrec,5,1)),
      Char6 = ascii(substring(tmrec,6,1))
    FROM Instr
    WHERE ISDATE(tmrec) = 0
    

    There is this Connect item that deals with SQL Server processing CAST on the SELECT clause before the WHERE filter has been applied. To overcome that, as also noted in the bug report, you can use a CASE statement:

    CAST(CASE WHEN ISDATE(tmrec)=1 THEN tmrec END as time)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am I just being blind or does this if statement genuinely not do what
In this statement, taken from the Pagerank source code: Pattern.compile(\\[.+?\\]); What does the pattern
As I am a MySQL newbie. What does PARTITION mean in this MySQL statement?
All are from this post . What does these statement mean: error(nargchk(5, 6, nargin));
Does this look like it should work? I'm wanting to generate directions from one
What does this Statement Mean... A cycle was detected in the build path of
What does this statement meaning, could somebody elaborate me on this please (@diplomaPercentage is
Where does this statement go? Do I put it in my constructor or do
Why does this statement work with OnKeyPress event of Javascript in C#. txtPassword.Attributes.Add(OnKeyUp, CheckPasswordStrength(\
What does this statement mean? //allocated memory for Device info (*PppsCoreStructure)->psDeviceDetails=(sDeviceDetails **)calloc(CORE_DEVICEINFO_SIZE, sizeof(sDeviceDetails*)); I

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.