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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:38:03+00:00 2026-05-20T19:38:03+00:00

SELECT Files.URL, Files.MD5, Files.Thumbnail, Files.Title, CONVERT(DATE, AttributeData.Keyword) AS DateUpdated, Attributes.Name AS DateType, Metadata.metadata FROM

  • 0
SELECT     Files.URL, Files.MD5, Files.Thumbnail, Files.Title, CONVERT(DATE, AttributeData.Keyword) AS DateUpdated, Attributes.Name AS DateType, 
                      Metadata.metadata
FROM         Files INNER JOIN
                      Metadata ON Files.ID = Metadata.FileID INNER JOIN
                      FilesToAttributeData ON Files.ID = FilesToAttributeData.FileID INNER JOIN
                      AttributeData ON FilesToAttributeData.AttributeDataID = AttributeData.ID INNER JOIN
                      Attributes ON AttributeData.AttributeID = Attributes.ID
WHERE       (Files.GeneralSearch = 1) AND 
            (Attributes.Name = 'Process Date' OR Attributes.Name = 'Publish Date') AND 
            (ISDATE(AttributeData.Keyword) = 1) AND 
            (CONVERT(DATE, AttributeData.Keyword) > DATEADD(DAY, - 90, GETDATE()))
ORDER BY DateUpdated DESC

This is my original sql query. It seems to work fine with our data in our dev environment. In production however I get the following error. “Msg 241, Level 16, State 1, Line 1
Conversion failed when converting date and/or time from character string.”. Now if I remove the convert function in the SELECT and just output AttributeData.Keyword it will work fine. If I leave that alone and remove the convert function in the where clause it will work fine. It will not work if they both exist though.

Any ideas what could cause this? I have tried CAST and I have tried using a specific date style. Our dates generally look like yyyymmdd. An example is ‘20110318’. If I replace AttributeData.Keyword with this string it will also fail. I really have no idea what is going on here.

Here is an example of a query that works.

SELECT     (AttributeData.Keyword) AS DateUpdated, Attributes.Name AS DateType

    FROM         Files INNER JOIN
                          Metadata ON Files.ID = Metadata.FileID INNER JOIN
                          FilesToAttributeData ON Files.ID = FilesToAttributeData.FileID INNER JOIN
                          AttributeData ON FilesToAttributeData.AttributeDataID = AttributeData.ID INNER JOIN
                          Attributes ON AttributeData.AttributeID = Attributes.ID
    WHERE       (Files.GeneralSearch = 1) AND 
                (Attributes.Name = 'Process Date' OR Attributes.Name = 'Publish Date') AND 
                (ISDATE(AttributeData.Keyword) = 1) AND 
                (CONVERT(DATE, AttributeData.Keyword) > DATEADD(DAY, - 90, GETDATE()))
    ORDER BY DateUpdated DESC

    DateUpdated DateType
    20110318    Process Date
    20110318    Process Date
    20110315    Process Date
    20110315    Process Date
    20110303    Process Date
    20110303    Publish Date
    20110302    Process Date
    20110301    Process Date
    20110301    Publish Date
    20110225    Process Date
    20110223    Process Date
    20110201    Publish Date
    20110201    Process Date
    20110127    Process Date
    20110118    Publish Date
    20110101    Publish Date
    20110101    Publish Date
    20101231    Process Date
    20101231    Publish Date
  • 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-20T19:38:04+00:00Added an answer on May 20, 2026 at 7:38 pm

    In SQL Server no particular order of evaluation is guaranteed except for CASE statements so it may well be doing the CONVERT(DATE, AttributeData.Keyword) before the ISDATE(AttributeData.Keyword) = 1 filter (you can confirm this by looking at the execution plans).

    To get around this you can replace CONVERT(DATE, AttributeData.Keyword) with

         CASE
               WHEN ISDATE(AttributeData.Keyword) = 1 THEN
               CONVERT(DATE, AttributeData.Keyword)
             END
    

    So can you try

    SELECT Files.URL,
           Files.MD5,
           Files.Thumbnail,
           Files.Title,
           CASE
             WHEN ISDATE(AttributeData.Keyword) = 1 THEN
             CONVERT(DATE, AttributeData.Keyword)
           END             AS DateUpdated,
           Attributes.Name AS DateType,
           Metadata.metadata
    FROM   Files
           INNER JOIN Metadata
             ON Files.ID = Metadata.FileID
           INNER JOIN FilesToAttributeData
             ON Files.ID = FilesToAttributeData.FileID
           INNER JOIN AttributeData
             ON FilesToAttributeData.AttributeDataID = AttributeData.ID
           INNER JOIN Attributes
             ON AttributeData.AttributeID = Attributes.ID
    WHERE  ( Files.GeneralSearch = 1 )
           AND ( Attributes.Name = 'Process Date'
                  OR Attributes.Name = 'Publish Date' )
           AND ( CASE
                   WHEN ISDATE(AttributeData.Keyword) = 1 THEN
                   CONVERT(DATE, AttributeData.Keyword)
                 END > DATEADD(DAY, -90, GETDATE()) )
    ORDER  BY DateUpdated DESC  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a select query that selects files with a thumbnail file attached and
We use OpenFileDialog across our application to select files. So far, we never used
is it possible to be able Multiple select files when make browse file? any
Currently when I open a file with my program I can select files on
I'm currently looking at ways to allow people to select multiple files at once
I have a page where users can select different documents files in a datalist
INSERT INTO files (fileUID, filename) WITH fileUIDS(fileUID) AS ( VALUES(1) UNION ALL SELECT fileUID+1
I have a form in a .html files where input/select box looks like this
I have a directory with about 2000 files. How can I select a random
I have tried django-filer to select mulitple files in a single filefield just 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.