473,386 Members | 1,835 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,386 software developers and data experts.

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.VwTransaction
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_General_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_General_CP1_CI_AS NOT NULL

) ON [PRIMARY]
GO

CREATE VIEW dbo.vwTransactions
AS
SELECT CONVERT(datetime, dbo.udf_AddDashes(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 2925
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.VwTransaction
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****@sommarskog.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
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...
0
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...
2
by: Leszek | last post by:
Hello! How can i enumerate creation data of files at different computer? For example in %systemdir%?
2
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:...
3
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...
1
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 :...
1
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 :...
1
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...
1
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.