导航
  • 主页
  • 基础类
  • 应用实例
  • 新技术前沿

字符串转换成日期出错啦!

firefox_1983 2006-01-24 01:28:13
declare @datestr varchar(10)
set @datestr='2006-1-24'
select * from ccdd where dt between convert(datetime,@datestr+'00:00:00',120 ) and convert(datetime,@datestr+'23:59:59',120)
从字符串转换为 datetime 时发生语法错误。怎么修改?
...全文
57 点赞 收藏 4
写回复
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lsqkeke 2006-01-24
或者:
select * from ccdd where dt between cast(@datestr+' 00:00:00' as datetime ) and cast(@datestr+' 23:59:59' as datetime)
回复
子陌红尘 2006-01-24
declare @datestr varchar(10)
set @datestr='2006-1-24'
select * from ccdd where dt between convert(datetime,@datestr+' 00:00:00',120 ) and convert(datetime,@datestr+' 23:59:59',120)
回复
WangZWang 2006-01-24
--中间少了空格
declare @datestr varchar(10)
set @datestr='2006-1-24'
select * from ccdd where dt between convert(datetime,@datestr+' 00:00:00',120 ) and convert(datetime,@datestr+' 23:59:59',120)
回复
lsqkeke 2006-01-24
select * from ccdd where dt between convert(datetime,@datestr+' 00:00:00',120 ) and convert(datetime,@datestr+' 23:59:59',120)

注意空格
回复
发动态
发帖子
MS-SQL Server
创建于2007-09-28

3.2w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
社区公告
暂无公告