话说,这句SQL是这样的,就处理这一列吧时间20080716000000
20080716000500
20080716001000



20080716234500


。如上,细心的看官应该看出来了,这是一个时间搞出来的字符串,现在呢,我想这样办比如您看前三行,分别是 20080716000000,20080716000500,20080716001000 。 首先 前面的20080716是时间,后面的000000,000500,001000,就是这个时间了,是0点到0点10分 当然 前面的日期以后肯定会变,还有比如20090802这样的,但是我们只处理后面的六位数的时间。好了,问题来了:我需要找出 这期间的 XXXXXXXXYY15YY 这样的所有的数据,就是说,前面的日期的20080715这八位数不管 后面时间的前后两位数不管,就找中间的,请问怎么找?我是这样写的,但是错了select Time case when substring(Time,11,2) in ('05','10','15') then '00'谢谢高手啦

解决方案 »

  1.   

    try~
    select Time 
    from tb
    where cast(substring(Time,11,2) as varchar(2)) in ('05','10','15') 
      

  2.   

    既然是字符串那直接用 like不就可以了吗
    select * from tb where listname like 'XXXXXXXXYY%'
      

  3.   

    '是这样的么????????????'
    use test
    go
    if object_id('test.dbo.tb') is not null drop table tb
    -- 创建数据表
    create table tb
    (
    时间 char(16)
    )
    go
    --插入测试数据
    insert into tb select '20080716000000'
    union all select '20080716000500'
    union all select '20080716001000'
    union all select '20080716001500'
    union all select '20080716002000'
    union all select '20080716011500'
    union all select '20080716112300'
    union all select '20080716111500'
    union all select '20080716234500'
    go
    --代码实现select * from tb where substring(时间,11,2)='15'/*测试结果时间
    ---------------------
    20080716001500  
    20080716011500  
    20080716111500  (3 行受影响)
    */