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

  • Home
  • SEARCH
  • 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 389243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:50:53+00:00 2026-05-12T15:50:53+00:00

So I have a base table that looks something like this. SELECT [BILL_MONTH] ,[BILL_YEAR]

  • 0

So I have a base table that looks something like this.

SELECT [BILL_MONTH]
      ,[BILL_YEAR]
      ,[BILLED]
 FROM bill_Detail

Everything is varchar.

I created a view based on that table that converts the bill year and bill month to a datetime field. Of course, the bill_month and bill_year fields have some crap data that doesn’t convert so I have the following WHERE clause in my view definition.

WHERE   ISDATE(CONVERT(varchar(4), BILL_YEAR)  + '-' + CONVERT(varchar(3), BILL_MONTH) + '-1' ) = 1

The view works like a champ when I do a plain select on it. No bad dates, everything cleaned up, etc. However, when I try and do any sort of date arithmetic (dateadd, datediff) I start getting conversion errors.

EDIT: Adding in actual view and test select statement:

Code for the view

SELECT  ID
    ,BILLED
    ,Payment_Type
    ,CONVERT(datetime, CONVERT(varchar(4), BILL_YEAR)  + '-'  + CONVERT(varchar(3), BILL_MONTH) + '-1' ) 
    AS BillDate FROM    dbo.Detail AS d WHERE   ISDATE(CONVERT(varchar(4), BILL_YEAR)  + '-' + CONVERT(varchar(3), BILL_MONTH) + '-1' ) = 1 AND     ISNULL(Payment_Code,'') = '' AND        Payment_Type in ('D','I')

Here is the select statement that blows up.

SELECT ID
  ,[BILLED]
  ,[Payment_Type]
  ,[BillDate] FROM vw_DelinquentDetail where isdate(billdate) = 1

The select statement is where the following error pops up.

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

Sorry for the code formatting on the first section.

  • 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-12T15:50:53+00:00Added an answer on May 12, 2026 at 3:50 pm

    make sure you cast or convert the date to a datetime in the view:

    create table testdates
    (BILL_MONTH  varchar(3)
    ,BILL_YEAR   char(4)
    ,BILLED char(1)
    )
    
    insert into testdates values ('01','2009','y')
    insert into testdates values ('02','2009','y')
    insert into testdates values ('03','2009','y')
    insert into testdates values ('a','bbb','n')
    
    create view testdates_v as
    select
    CONVERT(datetime,CONVERT(varchar(4), BILL_YEAR)  + '-' + CONVERT(varchar(3), BILL_MONTH) + '-1') as billdate
    from testdates
    WHERE   ISDATE(CONVERT(varchar(4), BILL_YEAR)  + '-' + CONVERT(varchar(3), BILL_MONTH) + '-1' ) = 1
    go
    

    now try to use the view:

    select billdate from testdates_v
    

    OUTPUT:

    billdate
    -----------------------
    2009-01-01 00:00:00.000
    2009-02-01 00:00:00.000
    2009-03-01 00:00:00.000
    
    (3 row(s) affected)
    
    
    select billdate+1,dateadd(mi,45,billdate) from  testdates_v
    

    output:

    ----------------------- -----------------------
    2009-01-02 00:00:00.000 2009-01-01 00:45:00.000
    2009-02-02 00:00:00.000 2009-02-01 00:45:00.000
    2009-03-02 00:00:00.000 2009-03-01 00:45:00.000
    
    (3 row(s) affected)
    

    EDIT after OP’s edit giving more code:

    SQL SERVER is probably trying to build out the billdate column before it applies the WHERE. As a result, change your view to select billdate using a CASE, so it is NULL when not a valid date:

    SELECT  ID
            ,BILLED
            ,Payment_Type
            ,CASE
                 WHEN ISDATE(CONVERT(varchar(4), BILL_YEAR)  + '-' + CONVERT(varchar(3), BILL_MONTH) + '-1' ) = 1  THEN CONVERT(datetime, CONVERT(varchar(4), BILL_YEAR)  + '-'  + CONVERT(varchar(3), BILL_MONTH) + '-1' ) 
                 ELSE NULL
             END AS BillDate 
        FROM    dbo.Detail AS d 
        WHERE   ISDATE(CONVERT(varchar(4), BILL_YEAR)  + '-' + CONVERT(varchar(3), BILL_MONTH) + '-1' ) = 1 AND         ISNULL(Payment_Code,'') = '' AND                Payment_Type in ('D','I')
    

    using the above view, the error goes away.

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

Sidebar

Ask A Question

Stats

  • Questions 286k
  • Answers 286k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Best solution was to make your own qstyle which handled… May 13, 2026 at 4:57 pm
  • Editorial Team
    Editorial Team added an answer import __builtin__ import StringIO class File(StringIO.StringIO): def __init__(self, *a, **k):… May 13, 2026 at 4:57 pm
  • Editorial Team
    Editorial Team added an answer Ultimately it would be the business owner or the person… May 13, 2026 at 4:57 pm

Related Questions

I've been doing some web development work in PHP recently which has led me
I have table in data base name train delay, with columns train number(int), DelayTime(int),
Never asked a question here before, I'll try to lay this out as succinctly
I'm having some performance issues in a rails project (running on rails 2.0.5), for

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.