我想找出id为1110728开头的数据,其中这个id是('1'+substring(CONVERT(varchar(12) , getdate(), 112 ),3,6))
select * from table where id like
这个like语句怎么写?其中id的第一位是不固定的1,2,3 

解决方案 »

  1.   

    select * from table1 
    where id like '_'+substring(CONVERT(varchar(12) , getdate(), 112 ),3,6)+'%'
      

  2.   

    select * from table1 
    where id like '[1-9]'+substring(CONVERT(varchar(12) , getdate(), 112 ),3,6)+'%'
      

  3.   

    --用变量
    declare 
        @mysql     varchar(8000),
        @head       int            --头ID
    set @head=**      --赋值给头ID
    set @mysql=N'select * from table where id like ('''+@head+'''+substring(CONVERT(varchar(12) , getdate(), 112 ),3,6))'
    exec (@mysql)
      

  4.   

    忘了在like里最后加)+'%',小失误
      

  5.   


    declare @id int
    set @id = 1  --楼主要查的select * from table1 
    where id like ltrim(@i)+substring(CONVERT(varchar(12) , getdate(), 112 ),3,6)+'%'
      

  6.   

    我找到解决方法了,'1'+substring(CONVERT(varchar(12) , getdate(), 112 )3,6)+'%'
    感谢大家