SQL SERVER 2000中迄今为止的Int

SQL SERVER 2000中迄今为止的Int,sql,sql-server,sql-server-2000,Sql,Sql Server,Sql Server 2000,如何将int列Birthdate(示例值20090301)转换为格式为(01/03/2009)的日期列 Sql Server 2000 我试着转换一些东西,比如下面的 select * from tabl where cast(dob as datetime)>='01/03/2009' which gives an error Msg 8115, Level 16, State 2, Line 1 Arithmetic overflow error converting expres

如何将int列Birthdate(示例值20090301)转换为格式为(01/03/2009)的日期列 Sql Server 2000

我试着转换一些东西,比如下面的

select * from tabl
where 
cast(dob as datetime)>='01/03/2009'
which gives an error

Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type datetime.
试试这个

select * from tabl
where 
cast(convert(char(8),dob, 112) as date)>='2009-03-01'

SQL Server不允许您直接强制转换int->datetime,但如果您确定可以先将其强制转换为nvarchar,然后将其强制转换为date。 对于你的问题,这里有一个例子

declare @test int = 20090301
select CONVERT(datetime, CAST(@test as nvarchar), 112)

112是您提到的格式,在转换函数的所有可能格式中。

您不想这样做。您希望将输入的
'01/03/2009'
转换为int
20090301
,这样您就可以使用
dob
上的索引快速找到您想要的行。相关-可能是因为SQL Server 2000中没有数据类型
date
。也可能是因为您正在where子句中的列上应用函数,这将使表达式不可搜索。