Author |
Topic |
MrMiagi
Starting Member
4 Posts |
Posted - 2012-05-11 : 02:53:54
|
Hi I'm running a SQL Server 2008 Express R2 database and recently one of the values in a date column on one of the tables have been corrupted. When ever I try to select the corrupt value I get the following error: An error occurred while executing batch. Error message is: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.When I cast that column to an INT it returns the value 67149661 which is why I get the overflow error. Now I am trying to either update or delete the record but when I try that I get yet another error: Msg 8630, Level 16, State 1, Line 1Internal Query Processor Error: The query processor encountered an unexpected error during execution.Is there any way that I can fix this value or at least remove it? I do have a backup with the original value. Thanks |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
MrMiagi
Starting Member
4 Posts |
Posted - 2012-05-11 : 03:11:22
|
Running the check returns the following error: Msg 2570, Level 16, State 3, Line 1Page (1:16731), slot 24 in object ID 213575799, index ID 1, partition ID 72057594096320512, alloc unit ID 72057594109034496 (type "In-row data"). Column "dtDate" value is out of range for data type "datetime". Update column to a legal value.It says I have to update the value but that I can't do. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2012-05-11 : 08:45:21
|
Yes you can by using the primary key.Is it a DATE or DATETIME column? N 56°04'39.26"E 12°55'05.63" |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2012-05-11 : 08:49:34
|
Is the date from 2011-09-13 00:00:00.000 ? N 56°04'39.26"E 12°55'05.63" |
|
|
MrMiagi
Starting Member
4 Posts |
Posted - 2012-05-11 : 09:35:02
|
quote: Originally posted by SwePeso Yes you can by using the primary key.Is it a DATE or DATETIME column? N 56°04'39.26"E 12°55'05.63"
Using the primary key give the same Internal Query error. It is a DATETIME column. |
|
|
MrMiagi
Starting Member
4 Posts |
Posted - 2012-05-11 : 09:37:36
|
quote: Originally posted by SwePeso Is the date from 2011-09-13 00:00:00.000 ? N 56°04'39.26"E 12°55'05.63"
Actually it is that exact same date! How did you know that ? |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2012-05-11 : 10:06:22
|
Magic... N 56°04'39.26"E 12°55'05.63" |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2012-05-11 : 10:21:42
|
Adjust this sample code to your environment. The code below should preserve the time part too.-- Prepare sample dataDECLARE @Sample TABLE ( RowID INT IDENTITY(1, 1) PRIMARY KEY CLUSTERED, dt DATETIME )-- Populate sample dataINSERT @SampleVALUES (GETDATE())-- Display the initial valueSELECT *FROM @Sample-- Start masking erraneous valueDECLARE @OldValue BINARY(8)-- Get the old value from sample tableSELECT @OldValue = CAST(dt AS BINARY(8))FROM @SampleWHERE RowID = 1-- Display the old binary valueSELECT @OldValue-- Mask the old value to get rid of out of range bitsSET @OldValue = @OldValue & CAST(0x0000FFFFFFFFFFFF AS BIGINT)-- Display new binary valueSELECT @OldValue-- Start updating the new valueDECLARE @NewValue DATETIME-- Convert the binary value to datetimeSET @NewValue = CAST(@OldValue AS DATETIME)-- Make the updateUPDATE @SampleSET dt = @NewValueWHERE RowID = 1-- Display the final valueSELECT *FROM @Sample Also see my blog post here for more information about the internal storage of datetime data typehttp://weblogs.sqlteam.com/peterl/archive/2010/11/05/the-internal-storage-of-a-datetime-value.aspx N 56°04'39.26"E 12°55'05.63" |
|
|
|