我疯了我,表里那个时间字段是这样的字段名: time属性:nvarchar(50)数据是这样子的:20080715221500  (看明白了吗,就是 2008年7月15日 22时15分00秒)------------------------------------------------------------------------现在我必须要把这些字段中,15分钟及以后的,处理为00分
大于15的 小于30的处理为30分,以此类推-----------------------------------------------------------------------于是我的SQL这样写的: sql11 = " update " + comboBox1.Text + "";
                    sql11 += " set newtime = left(time, 10) + case ";
                    sql11 += " when substring(time,11,2) in ('15') then '00'";
                    sql11 += " when substring(time,11,2) in ('30') then '15'";
                    sql11 += " when substring(time,11,2) in ('45') then '30'";
                    sql11 += " when substring(time,11,2) in ('00') then '45'";
                    sql11 += " when substring(time,11,2) in ('05','10') then '00'";
                    sql11 += " when substring(time,11,2) in ('20','25') then '15'";
                    sql11 += " when substring(time,11,2) in ('35','40') then '30'";
                    sql11 += " when substring(time,11,2) in ('50','55') then '45'";
                    sql11 += " end  + right(time,2)";这样的效率极度低下啊~~~~~~~~~~~~~~~~~求高手啊,告诉我这东西咋搞才能快点啊??高手~~~~------------------------------------------------------------------------我的思路,也许要修改字段属性?可是我改啥呢?反正改成datetime是改不了,咋整?

解决方案 »

  1.   

    select case when right(time,4) between '0000' and '1459' then '00'
                when right(time,4) between '1500' and '2959' then '15'
                when right(time,4) between '3000' and '4459' then '30'
                when right(time,4) between '4500' and '5959' then '45'
           end
    from tb
      

  2.   

    如果是update,则
    update set time = left(time,10) + 
           (case when right(time,4) between '0000' and '1459' then '00'
                 when right(time,4) between '1500' and '2959' then '15'
                 when right(time,4) between '3000' and '4459' then '30'
                 when right(time,4) between '4500' and '5959' then '45'
           end)
    from tb
      

  3.   

    create table T
    (id int identity,
    time varchar(50)
    )
    insert T
    select '20080715220000' union all
    select '20080715221000' union all
    select '20080715221500' union all
    select '20080715222500' union all
    select '20080715223000' union all
    select '20080715223500' union all
    select '20080715224500' union all
    select '20080715225000' union all
    select '20080715225500'
    select * from T
    /*
    id          time
    ----------- ---------------
    1           20080715220000
    2           20080715221000
    3           20080715221500
    4           20080715222500
    5           20080715223000
    6           20080715223500
    7           20080715224500
    8           20080715225000
    9           20080715225500(9 行受影响)*/
    update T
    set time = left(time,10) + right(ltrim((substring(time,11,2)+60-1)%60/15*15+100),2) + right(time,2)select * from Tid          time
    ----------- ----------------
    1           20080715224500
    2           20080715220000
    3           20080715220000
    4           20080715221500
    5           20080715221500
    6           20080715223000
    7           20080715223000
    8           20080715224500
    9           20080715224500(9 行受影响)