insert into 教室(编号,容纳人数,开放时间,关闭时间) values('E301',200,'6:00:00','21:30:00')插入后时间显示是1990-1-1 6:00:00  怎么把1990-1-1去掉,只保留6:00:00
  谢谢!!!!

解决方案 »

  1.   

    sql datetime类型就是这样的,
    1.你可以用varchar类型
    2.不用管它,当select 出来的时候用convert
      

  2.   

    哪个版本的数据库?
    如果是SQL2008,可以用TIME类型。
    如果是其他版本,最好用NVARCHAR吧。
      

  3.   

    --> 测试数据:[TB]
    if object_id('[TB]') is not null
    drop table [TB]---->建表
    create table [TB]([编号] varchar(4),[容纳人数] int,[开放时间] datetime,[关闭时间] datetime)
    insert [TB]
    select 'E301',200,'6:00:00','21:30:00'--> 查询结果
    SELECT *,stuff(convert(char(20),开放时间,120),1,10,'') as 开时 ,
    stuff(convert(char(20),关闭时间,120),1,10,'') as 关时 FROM [TB]
    --> 删除表格
    --DROP TABLE [TB]
      

  4.   

    select CONVERT(varchar,GETDATE(),108)
      

  5.   

     select @@VERSION
    /*
    Microsoft SQL Server 2008 (SP1) - 10.0.2531.0 (Intel X86) 
    Mar 29 2009 10:27:29 
    Copyright (c) 1988-2008 Microsoft Corporation
    Enterprise Edition on Windows NT 5.2 <X86> (Build 3790: Service Pack 2)
    */  declare @t table(编号 varchar(10),容纳人数 int,开放时间 time,关闭时间 time)
      insert @t select 'E301',200,'6:00:00','21:30:00'
      
      select * from @t
    /*
    编号         容纳人数        开放时间             关闭时间
    ---------- ----------- ---------------- ----------------
    E301       200         06:00:00.0000000 21:30:00.0000000
    */
      

  6.   

    正解是选择合适的类型:
    time 12:35:29.1234567 
    date 2007-05-08 
    smalldatetime 2007-05-08 12:35:00 
    datetime 2007-05-08 12:35:29.123 
    datetime2 2007-05-08 12:35:29.1234567 
    datetimeoffset 2007-05-08 12:35:29.1234567 +12:15 
      

  7.   

    这是最简便的方式。
    你可以在联机丛书中查一下关键字convert,很有意思的
      

  8.   


    select convert(varchar(20),开放时间,108) 开放时间,convert(varchar(20),关闭时间,108) 关闭时间 from 教室