繁体   English   中英

SQL SERVER 2000中的Int Date

[英]Int to Date in SQL SERVER 2000

如何将int列,Birthdate(样本值20090301)转换为格式为(01/03/2009)的date列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, 这是 Convert函数所有可能格式的列表

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM