原来在mysql中可以用substring来取数据库中时间的前几位,但是到sql2000就不行了,我想问在2000中怎么取时间的前几位,就是下面的语句在mysql中就能实行,但在2000中就不行了,怎么解决???RegDatetime是datetime类型的
String strSql1 = "select count(*) as A from cpd where substring(RegDatetime,1,7)<='2005-08' and CurState='1'";

解决方案 »

  1.   

    DATEPART
    Returns an integer representing the specified datepart of the specified date.Syntax
    DATEPART ( datepart , date ) Arguments
    datepartIs the parameter that specifies the part of the date to return. The table lists dateparts and abbreviations recognized by Microsoft&reg; SQL Server&#8482;.Datepart Abbreviations 
    year yy, yyyy 
    quarter qq, q 
    month mm, m 
    dayofyear dy, y 
    day dd, d 
    week wk, ww 
    weekday dw 
    hour hh 
    minute mi, n 
    second ss, s 
    millisecond ms 
      

  2.   

    select * from cpd where datepart(RegDatetime,7)<'2005-08'是这样吗?
      

  3.   

    也可使用SQL SERVER对日期类型的自动转换功能: String strSql1 = "select count(*) as A from cpd where RegDatetime<='2005-08-01 23:59:59' and CurState='1'";