簡體   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