读书人

从字符串向 datetime 转换时失败。该如

发布时间: 2012-02-05 12:07:14 作者: rapoo

从字符串向 datetime 转换时失败。
update t1
set t1.FDate=convert(datetime,cast(t2.FYear as varchar(4))+cast(FPeriod as varchar(2))),t1.FAmount=t2.FEndBal
from #cunhuo
where cast(t1.FPrice as varchar(255)) is null and t1.FQty>0

[解决办法]
try:
update t1
set t1.FDate=convert(datetime,cast(t2.FYear as varchar(4))+'-'+cast(FPeriod as varchar(2))+'01'),t1.FAmount=t2.FEndBal
from #cunhuo
where cast(t1.FPrice as varchar(255)) is null and t1.FQty>0
[解决办法]
还要一个短横:
update t1
set t1.FDate=convert(datetime,cast(t2.FYear as varchar(4))+'-'+cast(FPeriod as varchar(2))+'-01'),t1.FAmount=t2.FEndBal
from #cunhuo
where cast(t1.FPrice as varchar(255)) is null and t1.FQty>0
[解决办法]

SQL code
cast(t2.FYear as varchar(4))+cast(FPeriod as varchar(2))
[解决办法]
SQL code
update t1set t1.FDate=convert(datetime,cast(t2.FYear as varchar(4))+cast(FPeriod as varchar(2))+'01'),t1.FAmount=t2.FEndBalfrom #cunhuo  where cast(t1.FPrice as varchar(255)) is null and t1.FQty>0 

读书人网 >SQL Server

热点推荐