请问字符串转换成日期的问题 value只有数字吗?如果有字符串那可不行如果是数字,月份不能大于12,日期不能大于31你看表里的数据是否合法? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Left(cast([Value]as int),4) + '-' + Left(Right(cast([Value]as int),4),2) + '-' + Right(cast([Value]as int),2)不用转换直接datediff(day,forecastdate,[Value) 即可当然 我觉得你的 Value值可能包含不能转换成日期格式的数据 比如 20090229 或者 20091301 Try : 直接select datediff(day,forecastdate,cast([Value] as datetime)) 说明:(1) 字段 value 是数字;forecastdate是日期;(2)Left(cast([Value]as int),4) + '-' + Left(Right(cast([Value]as int),4),2) + '-' + Right(cast([Value]as int),2) 这个得出的是这样的结果: 2007-06-022006-12-212007-03-232007-03-30------------------现在的问题是:再加datediff()函数就有问题....报错:错误信息: Conversion failed when converting date and/or time from character string. (1) value 是 SmallDecimal数据类型;数字,如:67512000.00004204000.0000(2)forecastdate是日期,如:2007-01-31 00:00:002004-03-12 00:00:00(3)Left(cast([Value]as int),4) + '-' + Left(Right(cast([Value]as int),4),2) + '-' + Right(cast([Value]as int),2) 这个得出的是这样的结果:2007-06-022006-12-212007-03-232007-03-30 (4) 就是再往外扩:datediff()函数就报错了:语句执行报错:datediff(day,forecastdate,Left(cast([Value]as int),4) + '-' + Left(Right(cast([Value]as int),4),2) + '-' + Right(cast([Value]as int),2))=================================================== 急求答案 无奈,跪求各位大哥帮忙解决问题啊!!付费都行啊! 能否给个动态SQL的例子及解释?我的情况是这样的 50分,求几个SQL的公式,请指点一下!!! 将存储过程smzls_cjd_quanbu插入#d临时表该怎么写? 结构不同表的合并问题! Like用法——高手们帮忙啊 求助!!各位高手帮忙看看该怎么处理!急,先谢谢拉!! 很菜的问题 一个在sql中看似简单的问题,关于不同日期的流水号的生成,在线等 按指定的顺序进行显示 求个SQL
不用转换直接
datediff(day,forecastdate,[Value) 即可
当然 我觉得你的 Value值可能包含不能转换成日期格式的数据 比如 20090229 或者 20091301
直接
select datediff(day,forecastdate,cast([Value] as datetime))
(2)Left(cast([Value]as int),4) + '-' + Left(Right(cast([Value]as int),4),2) + '-' + Right(cast([Value]as int),2)
这个得出的是这样的结果:
2007-06-02
2006-12-21
2007-03-23
2007-03-30------------------
现在的问题是:再加datediff()函数就有问题....报错:
错误信息: Conversion failed when converting date and/or time from character string.
67512000.0000
4204000.0000(2)forecastdate是日期,如:
2007-01-31 00:00:00
2004-03-12 00:00:00(3)Left(cast([Value]as int),4) + '-' + Left(Right(cast([Value]as int),4),2) + '-' + Right(cast([Value]as int),2)
这个得出的是这样的结果:
2007-06-02
2006-12-21
2007-03-23
2007-03-30 (4) 就是再往外扩:datediff()函数就报错了:
语句执行报错:datediff(day,forecastdate,Left(cast([Value]as int),4) + '-' + Left(Right(cast([Value]as int),4),2) + '-' + Right(cast([Value]as int),2))===================================================