473,320 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

The conversion of a char data type to a datetime data type resulted in an out ofrange

syedshaffee
hey people,

when i am trying to execute a query i am getting
'The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.'ERROR
when i am generating for a short period EG:- form 1st jan to 15 jan for the same year.

here is the query can u people suggest me something
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT ADInvoice.InvoiceNo, ADInvoice.InvoiceDate, ADInvoice.InvoiceID AS InvoiceID, ADRVAllocation.ContractNo AS ContractNo, Sum(ADAsset.AssetPrice) AS SumOfAssetPrice, ADRVAllocation.ADRVAllocation, ADInvoice.InvoiceTotal, ADInvoice.InvoiceTypeID, ADInvoice.InvoiceGeneratedDate 
  2. FROM (ADInvoice LEFT JOIN ADRVAllocation ON ADInvoice.InvoiceID = ADRVAllocation.InvoiceID) LEFT JOIN ADAsset ON (ADRVAllocation.InvoiceID = ADAsset.AssetInvoiceID) AND (ADRVAllocation.ContractNo = ADAsset.AssetContractNo) 
  3. GROUP BY ADInvoice.InvoiceNo, ADInvoice.InvoiceDate, ADInvoice.InvoiceID, ADRVAllocation.ContractNo, ADRVAllocation.ADRVAllocation, ADInvoice.InvoiceTotal, ADInvoice.InvoiceTypeID, ADInvoice.InvoiceGeneratedDate 
  4. HAVING ((ADInvoice.InvoiceTypeID=2) AND (ADInvoice.InvoiceGeneratedDate BETWEEN convert(DATETIME,'31-01-2012',110) AND CONVERT(DATETIME,GETDATE(),110)))
  5. Union 
  6. SELECT DISTINCT ADInvoice.InvoiceNo, ADInvoice.InvoiceDate, ADAsset.AssetDamagesInvoiceID AS InvoiceID, ADRVAllocation.ContractNo AS ContractNo, Sum(ADAsset.AssetInvoiceCost) AS SumOfAssetPrice, ADRVAllocation.ADRVAllocation, ADInvoice.InvoiceTotal, ADInvoice.InvoiceTypeID, ADInvoice.InvoiceGeneratedDate 
  7. FROM (ADInvoice LEFT JOIN ADRVAllocation ON ADInvoice.InvoiceID = ADRVAllocation.InvoiceID) LEFT JOIN ADAsset ON (ADRVAllocation.InvoiceID = ADAsset.AssetInvoiceID) AND (ADRVAllocation.ContractNo = ADAsset.AssetContractNo) 
  8. GROUP BY ADInvoice.InvoiceNo, ADInvoice.InvoiceDate, ADAsset.AssetDamagesInvoiceID, ADRVAllocation.ContractNo, ADRVAllocation.ADRVAllocation, ADInvoice.InvoiceTotal, ADInvoice.InvoiceTypeID, ADInvoice.InvoiceGeneratedDate 
  9. HAVING ADAsset.AssetDamagesInvoiceID Is Not Null AND ADInvoice.InvoiceTypeID=2 AND ADInvoice.InvoiceGeneratedDate >= convert(DATETIME,'01/01/2012',110) AND ADInvoice.InvoiceGeneratedDate <= CONVERT(DATETIME,GETDATE(),110)
  10.  
Feb 3 '12 #1

✓ answered by Stewart Ross

Three observations. The first is that you are specifying US format (mm/dd/yyyy) in your convert statement, yet you are supplying a UK or other non-US format date literal in line 4 of the code above. Second observation relating to the same date literal is that it is supplied using dash separators rather than slash separators - I don't know if that is significant or not but it is inconsistent at best.

The statement concerned is:

Expand|Select|Wrap|Line Numbers
  1. convert(DATETIME,'31-01-2012',110)
which should be

Expand|Select|Wrap|Line Numbers
  1. convert(DATETIME,'01/31/2012',110)
The third observation is that you are using Convert on the system GetDate function which seems a bit redundant to me, as GetDate already returns a value of type datetime. For example, in line 9 above:

Expand|Select|Wrap|Line Numbers
  1. CONVERT(DATETIME,GETDATE(),110)
-Stewart

6 7247
Rabbit
12,516 Expert Mod 8TB
You should look at the actual date values and make sure they're within range. If you don't see which one is causing the error, post some of the date values.
Feb 3 '12 #2
Expand|Select|Wrap|Line Numbers
  1. ---+----------------------+---+----------------------+
  2. ID | Intent Date          |ADI| Invoice_date         |
  3. ---+----------------------+---+----------------------+
  4. 1  |01/01/2005 12:00:00 AM|43 |01/01/2005 12:00:00 AM|
  5. ---+----------------------+---+----------------------+
  6.  
This are some data values form My table

can u Suggest me How do i resolve the Error
Feb 3 '12 #3
Stewart Ross
2,545 Expert Mod 2GB
Three observations. The first is that you are specifying US format (mm/dd/yyyy) in your convert statement, yet you are supplying a UK or other non-US format date literal in line 4 of the code above. Second observation relating to the same date literal is that it is supplied using dash separators rather than slash separators - I don't know if that is significant or not but it is inconsistent at best.

The statement concerned is:

Expand|Select|Wrap|Line Numbers
  1. convert(DATETIME,'31-01-2012',110)
which should be

Expand|Select|Wrap|Line Numbers
  1. convert(DATETIME,'01/31/2012',110)
The third observation is that you are using Convert on the system GetDate function which seems a bit redundant to me, as GetDate already returns a value of type datetime. For example, in line 9 above:

Expand|Select|Wrap|Line Numbers
  1. CONVERT(DATETIME,GETDATE(),110)
-Stewart
Feb 3 '12 #4
NeoPa
32,556 Expert Mod 16PB
I've just added a post to Literal DateTimes and Their Delimiters (#) explaining where the #yyyy-mm-dd# date format fits into the ANSI SQL standards. It's sort of supported in Jet (Access SQL), but fully supported in SQL Server. The new link in the article gives an MSDN page with full details for SQL Server.

The short version is that it's a perfectly valid and standard format for SQL date literals though.
Feb 5 '12 #5
Okay people now i checked it working fine in sql server 2005 but when I'm executing on my front end it gives me an ODBC ERROR:3151 can u suggest me some thing
Feb 6 '12 #6
NeoPa
32,556 Expert Mod 16PB
From an error number on its own? I doubt it.

You need to post the error message, your code and something to indicate whereabout in your code the error occurred. I would have thought that would be obvious.

PS. OP has posted this question separately under How to reslove ODBC 3151: Error, so please address any answers to this question there and not here. This question can be considered to be closed.
Feb 6 '12 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Amir | last post by:
Hi all, I have a table called PTRANS with few columns (see create script below). I have created a view on top that this table VwTransaction (See below) I can now run this query without a...
3
by: arijitchatterjee123 | last post by:
Hi Group, I am new with SQL Server..I am working with SQL Server 2000. I am storing the date in a nvarchar column of atable.... Now I want to show the data of Weekends..Everything is OK...But the...
0
by: James | last post by:
I am using an sqldatareader and trying to add items from a sql select statement to a listview control. All columns from sql select statement are added into listview except one column that is a sql...
1
by: dcrespo | last post by:
Hi to all, I have functions defined in an xml-rpc server. Some functions query to a Postgres database (using adodb) and return its recordset. So, if some xml-rpc client runs the mentioned...
4
by: Saso Zagoranski | last post by:
Hi! I have created an SqlCommand object and I have set some parameters to it... One of the parameters is of the DateTime type; here is the code: sqlCommand.Parameters.Value =...
1
by: M DL via .NET 247 | last post by:
Hi all, i have one problem with a method of an xml web service that use a datetime data type input variable, and may be all is caused by international settings. The XML web service (localized...
13
by: Alan M Dunsmuir | last post by:
I need to specify a new data type, almost entirely a 'clone' of the existing DateTime type, with the following specific difference, and all the consequent differences in properties and methods...
1
by: A.Neves | last post by:
Hi, I'm having a problem, I have a DateTime value in Portuguese representation (dd-mm-yyyy) and I'm using SQLServer2005 with its default language English (yyyy-mm-dd), so when I assemble a WHERE...
3
by: paul_zaoldyeck | last post by:
i have another problem.and it's now on converting a char(4) to datetime here is the situation J_TIM < F_TIM J_TIM is datetime while F_TIM is char of 4 example J_TIM = 20:30 F_TIM = 2030
2
by: Thomas609 | last post by:
Hi, I want to update a column typed datetime. My statement is: update 'tablename' set Datum_Ende = '2007-12-17 08:49:04.000' where 'columnID_name' = 23250 and 'columndate_Name' =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.