473,765 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Index creation causes error "The conversion of a char data type to a datetime data type resulted..."

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 problem:

select * from dbo.VwTransacti on
where
AssetNumber = '101001' and
TransactionDate <= '7/1/2003'

But when I create an index on the PTRANS table using the command below:

CREATE INDEX IDX_PTRANS_CHL# ON PTRANS(CHL#)

The same query that ran fine before, fails with the error:

Server: Msg 242, Level 16, State 3, Line 1
The conversion of a char data type to a datetime data type resulted in
an out-of-range datetime value.

I can run the same query by commeting out the AssetNumber clause and it
works fine. I can also run the query commenting out the TransactionDate
column and it works fine. But when I have both the conditions in the
WHERE clause, it gives me this error. Dropping the index solves the
problem.

Can anyone tell me why an index would cause a query to fail?

Thanks a lot in advance,
Amir



CREATE TABLE [PTRANS] (
[CHL#] [varchar] (100) COLLATE SQL_Latin1_Gene ral_CP1_CI_AS NULL ,
[CHCENT] [numeric](2, 0) NOT NULL ,
[CHYYMM] [numeric](4, 0) NOT NULL ,
[CHDAY] [numeric](2, 0) NOT NULL ,
[CHTC] [char] (2) COLLATE SQL_Latin1_Gene ral_CP1_CI_AS NOT NULL

) ON [PRIMARY]
GO

CREATE VIEW dbo.vwTransacti ons
AS
SELECT CONVERT(datetim e, dbo.udf_AddDash es(REPLICATE('0 ', 2 -
LEN(CHCENT)) + CONVERT(varchar , CHCENT) + REPLICATE('0', 4 -
LEN(CHYYMM))
+ CONVERT(varchar , CHYYMM) + REPLICATE('0', 2 -
LEN(CHDAY)) + CONVERT(varchar , CHDAY)), 20) AS TransactionDate ,
CHL# AS AssetNumber,
CHTC AS TransactionCode
FROM dbo.PTRANS
WHERE (CHCENT <> 0) AND (CHTC <> 'RA')

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #1
1 2959
Amir (no****@devdex. com) writes:
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 problem:

select * from dbo.VwTransacti on
where
AssetNumber = '101001' and
TransactionDate <= '7/1/2003'

But when I create an index on the PTRANS table using the command below:

CREATE INDEX IDX_PTRANS_CHL# ON PTRANS(CHL#)

The same query that ran fine before, fails with the error:

Server: Msg 242, Level 16, State 3, Line 1
The conversion of a char data type to a datetime data type resulted in
an out-of-range datetime value.
...
Can anyone tell me why an index would cause a query to fail?


Apparently the table includes data from which a date cannot be composed
(or which your view does not handle properly.)

In this case it's up to chance whether this value would cause trouble
like the one above. If SQL Server first filters on AssetNumber, you
are fine, if the bad date is for another asset number. But if SQL Server
first looks at the date, you lose.

As for your view, I'm a little worried about the add_dashes thing.
Stick to the format YYYYMMDD HH:MM:SS, since this format is always
understood by SQL Server.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3205
by: lyn.duong | last post by:
Hi, I've got this dts package in sql server 2000 sp4 that has several transformation tasks with an oracle database (10g) as the destination. The package executes successfully when run through the dts designer but when run using dtsrun, I get the following error at the completion of all tasks in the dts package. The data inserts into the oracle database but i always get this Application error The Instruction at "0x7c8327f9" referenced...
0
1113
by: **Developer** | last post by:
This is almost the same as a previous post that is still giving me a problem, but with a different slant. I can't seem to find out what is wrong. My program crashes after it leaves an event handler. It is an event that is raised by Net's ListBox. The form handling the event, as described below, contains a UserControl that inherits from ListBox but does not handle nor override the event in question. So the stack contains only the handler...
2
978
by: Leszek | last post by:
Hello! How can i enumerate creation data of files at different computer? For example in %systemdir%?
2
1881
by: Martin v. Löwis | last post by:
I've been working on PEP 353 for some time now. Please comment, in particular if you are using 64-bit systems. Regards, Martin PEP: 353 Title: Using ssize_t as the index type Version: $Revision: 42333 $
3
5267
by: Dan | last post by:
Hi, I'm learning asp.net 2.0 and i get this error: "Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource" My code: Dim a As GridView Dim oConnection As OleDbConnection oConnection = New OleDbConnection()
1
3973
by: BillAtWork | last post by:
Hi, I'm trying to validate an XML document against an XSD schema and I receive the following error: ---------- MyCode.CreateValidRequest : System.Web.Services.Protocols.SoapException : Validation error: The element 'http://xmlns.somewhere.com/something:rDetail' cannot contain text. Expected 'http://xmlns.somewhere.com/something:AList'. An error occurred at , (1, 533). ----------
1
2583
by: BillAtWork | last post by:
Hi, I'm trying to validate an XML document against an XSD schema and I receive the following error: ---------- MyCode.CreateValidRequest : System.Web.Services.Protocols.SoapException : Validation error: The element 'http://xmlns.somewhere.com/something:rDetail' cannot contain text. Expected 'http://xmlns.somewhere.com/something:AList'. An error occurred at , (1, 533). ----------
1
1558
by: senthilganga | last post by:
Hello, I use a simple list-based drop-down menu : The problem is that there is a z-index issue in IE6 that causes the menu to be placed BEHIND <select> input items. I understand that this can be fixed using IFRAMEs but I don't know how to do this myself and I ONLY want the iFrame fix to be applied to users of IE5.5 or IE6. How can this be done?
1
3887
by: mudasserrafiq | last post by:
I am using following asp file default.asp <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <META http-equiv=Content-Type content="text/html; charset=windows-1252"> <META content="0 Days" name=revisit-after> <META content=info@siderinternational.com name=email> <META content="Omer Safdar" name=author> <META content=MegaStudios.com name=publisher> <META content="Copyright ©2005 - MegaStudios.com" name=copyright> <SCRIPT...
1
3756
by: kamcap | last post by:
I have referenced a COM dll (unmanagged code) in a C# console application and this DLL is referenced in C# program using Interop facility in .NET. This dll actually a dataset/table which is written in Borland Delphi. static int Main(string args) { ClientVarDataSet vds = new ClientVarDataSet(); vds.XML = ""; vds.AddField("x", 3); //"x" field name and 3 field type
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9957
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9835
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8832
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.