|
|
Question : Arithmetic overflow error converting expression to data type datetime
|
|
I have a SQL Serve table with a date filed that has data that is not similiar.
CREATE TABLE [dbo].[tbl_research_mktcap_index]( [autoid] [int] IDENTITY(1,1) NOT NULL, [_date] [nvarchar](50) NULL, [allshareindex] [nvarchar](50) NULL, [marketcap] [nvarchar](50) NULL, [deals] [nvarchar](50) NULL, [volume] [nvarchar](50) NULL, [_value] [nvarchar](50) NULL,
The _date filed is not a real data field but the data in this database is a date. The dates come in the following format
07-May-03 also 07/05/2003 and also 07-05-03
The problem is , the database was originally an access database and so I could use the following SQL statement
strSQL = "SELECT DISTINCT YEAR([_date]) As Year FROM tbl_research_mktcap_index ORDER BY 1"
and it worked, but now with MSSQL, I get the following error message
[Microsoft][ODBC SQL Server Driver][SQL Server]Arithmetic overflow error converting expression to data type datetime
How do I make MSSQL see the _date cells as date data?
HELP PLEASE!
|
Answer : Arithmetic overflow error converting expression to data type datetime
|
|
something like strSQL = "SELECT DISTINCT YEAR(CAST([_date] AS datetime)) As Year FROM tbl_research_mktcap_index where (not (_date is null)) or (_date='') ORDER BY 1"
|
|
|
|
|