用最简单的方法向table1的time字段插入一天的整点时间1:00
2:00
3:00
4:00
5:00
6:00
7:00
8:00
9:00
10:00
11:00
12:00
13:00
14:00
15:00
16:00
17:00
18:00
19:00
20:00
21:00
22:00
23:00越简单越好,最好一条语句搞定

解决方案 »

  1.   

    SELECT LTRIM(NUMBER)+':00' 
    FROM MASTER..SPT_VALUES W
    HERE TYPE='P' AND NUMBER BETWEEN 1 AND 24
      

  2.   

    select ltrim(number+1)+':00'
    from master..spt_values
    where type='P' and number<=22
    /*
    1:00
    2:00
    3:00
    4:00
    5:00
    6:00
    7:00
    8:00
    9:00
    10:00
    11:00
    12:00
    13:00
    14:00
    15:00
    16:00
    17:00
    18:00
    19:00
    20:00
    21:00
    22:00
    23:00*/
      

  3.   


    P没到NUMBER BETWEEN 1 AND 23
      

  4.   

    SELECT top 24 ltrim(row_number()over(order by getdate())-1)+':00' FROM sysobjects
    /*
    ---------------------------
    0:00
    1:00
    2:00
    3:00
    4:00
    5:00
    6:00
    7:00
    8:00
    9:00
    10:00
    11:00
    12:00
    13:00
    14:00
    15:00
    16:00
    17:00
    18:00
    19:00
    20:00
    21:00
    22:00
    23:00(24 行受影响)
    */
      

  5.   


    insert table1 (time)
    select'1:00'union all
    select'2:00'union all
    select'3:00'union all
    select'4:00'union all
    select'5:00'union all
    select'6:00'union all
    select'7:00'union all
    select'8:00'union all
    select'9:00'union all
    select'10:00'union all
    select'11:00'union all
    select'12:00'union all
    select'13:00'union all
    select'14:00'union all
    select'15:00'union all
    select'16:00'union all
    select'17:00'union all
    select'18:00'union all
    select'19:00'union all
    select'20:00'union all
    select'21:00'union all
    select'22:00'union all
    select'23:00'