默认值取getdate()就取了日期和时间
convert(char(10),getdate(),120)是否就取是在调用的时候取了,是不是变成char型了?
影响查询不?
请指教!!!

解决方案 »

  1.   

    sql server中就只有datetime型能保存日期或时间,所以如果只要日期不要时间,就只能转成字符型了
      

  2.   

    [code=Sql]
    Create Table #tempS
    (
    S Smalldatetime
    )
    insert #tempS select '20080101' union all select '20080901'
    go
    select *,convert(char(10),getdate(),120) as todate from #tempS Where S>convert(char(10),getdate(),120)
    --不会影响
    /*
    S                       todate
    ----------------------- ----------
    2008-09-01 00:00:00     2008-07-29
    */
    [/Sql]
      

  3.   

     是变成了char型,因为是显式转换,但与日期类型数据运算时
    日期格式(//..--)的字符型数据会隐性自动转换成日期型数据,所以不影响查询