可以啊:
declare @str varchar(20)
set @str='20040910'
select cast(@str as smalldatetime)

解决方案 »

  1.   

    declare @str varchar (8)
    set @str='20040901'
    select 
    cast(@str as smalldatetime)
      

  2.   

    这样转会出错:
    declare @i  int 
    set @i=20040910
    select cast(@i as smalldatetime)
      

  3.   

    --两个都可以cast convert
    declare @str char(8)
    set @str='20040910'
    select cast(@str as smalldatetime)
    select convert(smalldatetime,@str,120)
      

  4.   

    --为int时这样
    declare @i  int 
    set @i=20040910
    select convert(smalldatetime, cast(@i as varchar(20)))
      

  5.   

    如果是非法日期,错误:
    从 char 数据类型到 smalldatetime 数据类型的转换导致 smalldatetime 值越界
    就是你说的溢出吧
      

  6.   

    为20040931时出错的:
    从 char 数据类型到 smalldatetime 数据类型的转换导致 smalldatetime 值越界。