SQL SERVER 2000 中的 Into Date [英] Int to Date in SQL SERVER 2000

查看:42
本文介绍了SQL SERVER 2000 中的 Into Date的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 int 列,出生日期(样本值 20090301)转换为格式(01/03/2009)的日期列SQL Server 2000

How to convert an int column ,Birthdate( sample value 20090301) to a date column in the format(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.

推荐答案

SQL Server 不允许直接转换 int -> datetime,但是如果您确定可以先转换为 nvarchar,然后再转换为日期.对于你的问题,这里有一个例子

SQL Server doesn't allow you to cast int -> datetime directly, but if you're sure you can cast it to nvarchar first and then cast it to date. For your question here's an example

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

112 是您提到的格式,这里是 Convert 的所有可能格式的列表功能.

112 is the format you mentioned, here's the list of all possible formats for Convert function.

这篇关于SQL SERVER 2000 中的 Into Date的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆