可以的~~由于时间原因我就不详细举例子了:(你把三个字段的值Cast成Char型!
然后相加,再把它转换成DateTime型!
如:cast((cast(YearField) as Char(4)) + cast(MonthField) as Char(2)) + cast(DayField) as Char(4))) as DateTime)注:以上语句不能保证正确!

解决方案 »

  1.   

    select * from clue where (cast(jbsjn+ jbsjy+ jbsjr)as DateTime)>= '2002-7-20' 报告了 服务器: 消息 1035,级别 15,状态 10,行 1
    'cast' 附近有语法错误,需要 'AS'。 怎么办呢?:(
      

  2.   

    select * from clue where (cast(jbsjn+jbsjy+jbsjr) as DateTime)>= '2002-7-20'
      

  3.   

    Select cast((cast(2002 as Char(4)) + '-' + cast(07 as Char(2)) + '-' + cast(28 as Char(2))) as datetime) as NewDate上面的语句我已经测试过了~~可以的,
    你只要把
    2002 -> 年的字段
    07 -> 月的字段
    02 - > 日的字段
      

  4.   

    是不是年,月,日字符?
    select * from tbl1
    where convert(datetime,yearfield+monthfield+dayfield) between '2002-3-20' and '2002-4-20'
      

  5.   

    Select cast((cast(2002 as Char(4)) + '-' + cast(07 as Char(2)) + '-' + cast(28 as Char(2))) as datetime) as NewDate上面的语句我已经测试过了~~可以的,
    你只要把
    2002 -> 年的字段
    07 -> 月的字段
    02 - > 日的字段 //版 主的convert(datetime,yearfield+monthfield+dayfield) 好像不行啊~
    我测试了一下,如果有更好的解决方法,告诉我一声哦:)
      

  6.   

    Select convert(datetime, 2002+07+28)输出结果:
    1905-07-31 00:00:00.000
    ??!
      

  7.   

    Select * from clue where  
    (cast((cast(jbsjn as Char(4)) + '-' + cast(jbsjy as Char(2)) + '-' + cast(jbsjr as Char(2))) as datetime) as NewDate) >='2002-2-2'
    报告了在关键字 'as' 附近有语法错误。
      

  8.   

    Select * from clue where  
    cast((cast(jbsjn as Char(4)) + '-' + cast(jbsjy as Char(2)) + '-' + cast(jbsjr as Char(2))) as datetime) >='2002-2-2'
      

  9.   

    Select * from clue where  
    cast((cast(jbsjn as Char(4)) + '-' + cast(jbsjy as Char(2)) + '-' + cast(jbsjr as Char(2))) as datetime) >='2002-2-2'
      

  10.   

    条件是: 年,月,日字符,即然字段值是,07 08 那一般是CHAR VARCHAR 型
    Select convert(datetime, '2002'+'07'+'28')
    Select cast('2002'+'07'+'28' as datetime)
    结果:2002-07-28 00:00:00.000
      

  11.   

    Select convert(datetime, 2002+07+28) 当然不对
    应是:Select convert(datetime,'2002'+'07'+'28')
    如果年月日字段安符型的,才可直接加,
    Select convert(datetime,'2002'+'07'+'28')
    Select cast('2002'+'07'+'28' as datetime)2002-07-08 00:00:00.000