Sql server 日期型与数值型的转换....
来源:互联网 发布:网络电视盒子哪个品牌好 编辑:程序博客网 时间:2024/06/08 02:25
---问题---
/*
现在遇到一个问题: 数据库是sql server2000,前台录入的是时间,但是数据库中存的确是int型,
如果我要按照日期查找(例如找2007-3-12到2007-3-24的数据),我应该如何写sql语句. 假设表名为test,
保存日期的字段名为open_date.
*/
declare
@test table
(open_date int)
declare @i_date datetime
set @i_date='2007-02-01'
insert into @test select convert(int,@i_date)i_date
set @i_date='2007-03-01'
insert into @test select convert(int,@i_date)i_date
set @i_date='2007-03-12'
insert into @test select convert(int,@i_date)i_date
set @i_date='2007-03-13'
insert into @test select convert(int,@i_date)i_date
select * from @test
select open_date, convert(datetime,open_date)as new_date from @test
where convert(datetime,open_date)>='2007-3-12'
and convert(datetime,open_date)<='2007-3-24'
---运行结果--
open_date
-----------
39112
39140
39151
39152
(4 row(s) affected)
open_date new_date
----------- ------------------------------------------------------
39151 2007-03-12 00:00:00.000
39152 2007-03-13 00:00:00.000
(2 row(s) affected)
- Sql server 日期型与数值型的转换....
- double数值与日期型之间的相互转换
- sql server 的 日期转换
- SQL SERVER的日期转换
- SQL Server和Oracle日期与字符串之间的转换
- sql server日期函数以及与字符串的转换
- 5、SQL Server:sqlserver 日期与字符串之间的转换
- sql server 日期与字符串转换
- SQL Server日期格式的转换
- SQL Server日期格式的转换
- SQL Server日期格式的转换
- SQL Server日期格式的转换
- SQL Server日期格式的转换
- SQL Server日期格式的转换
- SQL Server日期格式的转换
- SQL Server日期格式的转换
- SQL Server日期格式的转换
- SQL Server日期格式的转换
- Test Drive Unlimited (2007)
- 我学汇编--计数器的例子
- Pro OpenSSH (Pro) by Michael Stahnke
- Sql Server Some Question --Case...Whne...(2)
- Free/Open Source Software Development by Stefan Koch
- Sql server 日期型与数值型的转换....
- What GPS is
- GTK+主循环(main loop)的工作原理
- Sql server identity字段的重新定位...
- 建造模式
- web form md5与winform md5不一样 得到解决
- Visual C# .NET Programming
- 该怎样去爱一个人
- 一段取值的sql...(charindex的应用)