日期:2014-05-18  浏览次数:20536 次

从字符串向 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 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