declare @time1 datetime
declare @tcont varchar(50)
set @tcont=substring('20070815123645',1,4)+'-'+substring('20070815123645',5,2)+'-'+substring('20070815123645',7,2)+' '+substring('20070815123645',9,2)+':'+substring('20070815123645',11,2)+':'+substring('20070815123645',13,2)
set @time1=convert(datetime,@tcont)insert into locationss (id,time) values (12,@thetime)
其中time字段是datetime类型的。。
提示出错:从字符串转换成datetime类型错误。。
各位帮忙看看怎么回事啊?

解决方案 »

  1.   

    declare @table table(id int,time datetime)
    declare @time1 datetime
    declare @tcont varchar(50)
    set @tcont=substring('20070815123645',1,4)+'-'+substring('20070815123645',5,2)+'-'+
    substring('20070815123645',7,2)+' '+substring('20070815123645',9,2)+':'+
    substring('20070815123645',11,2)+':'+substring('20070815123645',13,2)
    set @time1=convert(datetime,@tcont)
    insert into @table values(12,@time1)
    select*from @table
    ---没问题啊,大虾,你的insert into locationss (id,time) values (12,@thetime)
    写错了吧。@thetime改成@time1。