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 -
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
-
FROM (ADInvoice LEFT JOIN ADRVAllocation ON ADInvoice.InvoiceID = ADRVAllocation.InvoiceID) LEFT JOIN ADAsset ON (ADRVAllocation.InvoiceID = ADAsset.AssetInvoiceID) AND (ADRVAllocation.ContractNo = ADAsset.AssetContractNo)
-
GROUP BY ADInvoice.InvoiceNo, ADInvoice.InvoiceDate, ADInvoice.InvoiceID, ADRVAllocation.ContractNo, ADRVAllocation.ADRVAllocation, ADInvoice.InvoiceTotal, ADInvoice.InvoiceTypeID, ADInvoice.InvoiceGeneratedDate
-
HAVING ((ADInvoice.InvoiceTypeID=2) AND (ADInvoice.InvoiceGeneratedDate BETWEEN convert(DATETIME,'31-01-2012',110) AND CONVERT(DATETIME,GETDATE(),110)))
-
Union
-
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
-
FROM (ADInvoice LEFT JOIN ADRVAllocation ON ADInvoice.InvoiceID = ADRVAllocation.InvoiceID) LEFT JOIN ADAsset ON (ADRVAllocation.InvoiceID = ADAsset.AssetInvoiceID) AND (ADRVAllocation.ContractNo = ADAsset.AssetContractNo)
-
GROUP BY ADInvoice.InvoiceNo, ADInvoice.InvoiceDate, ADAsset.AssetDamagesInvoiceID, ADRVAllocation.ContractNo, ADRVAllocation.ADRVAllocation, ADInvoice.InvoiceTotal, ADInvoice.InvoiceTypeID, ADInvoice.InvoiceGeneratedDate
-
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)
-
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: - convert(DATETIME,'31-01-2012',110)
which should be - 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: - CONVERT(DATETIME,GETDATE(),110)
-Stewart
6 7247
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.
-
---+----------------------+---+----------------------+
-
ID | Intent Date |ADI| Invoice_date |
-
---+----------------------+---+----------------------+
-
1 |01/01/2005 12:00:00 AM|43 |01/01/2005 12:00:00 AM|
-
---+----------------------+---+----------------------+
-
This are some data values form My table
can u Suggest me How do i resolve the Error
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: - convert(DATETIME,'31-01-2012',110)
which should be - 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: - CONVERT(DATETIME,GETDATE(),110)
-Stewart
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.
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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 =...
|
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...
|
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...
|
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...
|
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
|
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' =...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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...
|
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....
|
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...
|
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...
| |