select * from 表 where ciyt like '%substring(''1301'',1,2)%'

解决方案 »

  1.   

    --测试数据
    select *
    into city
    from
    (
    select '1100,1200,1301' city
    union
    select '1100,1200,1300'
    union
    select '1101,1200,1301'
    union  
    select '1200,1301'
    )
    info--查询
    declare @s_parm varchar(20)
    declare @s_sql varchar(200)
    set @s_parm = '1201'
    select *
    from city
    where patindex('%,' + @s_parm + ',%',','+ city + ',') > 0 or
        patindex('%,' + left(@s_parm,2) + '%',','+ city + ',') > 0 --删除测试数据
    drop table city
      

  2.   

    --测试数据
    select *
    into city
    from
    (
    select '1100,1200,1301' city
    union
    select '1100,1200,1300'
    union
    select '1101,1200,1301'
    union  
    select '1200,1301'
    )
    info--查询
    declare @s_parm varchar(20)
    declare @s_sql varchar(200)
    set @s_parm = ',1201,1101,'select distinct
    city
    from 
    city,
    (select distinct top 50 
    colid,
    substring(@s_parm,colid + 1,charindex(',',@s_parm,colid + 1) - colid - 1) parm
    from syscolumns
    where substring(@s_parm,colid,1) = ',' and 
          charindex(',',@s_parm,colid + 1) <> 0
    order by colid
    ) info
    where patindex('%,' + info.parm + ',%',','+ city + ',') > 0 or
        patindex('%,' + left(info.parm,2) + '%',','+ city + ',') > 0 --删除测试数据
    drop table city
      

  3.   

    wudan8057(十年人生)  哈,谢谢你,
    如果针对你的算法,10W条记录判断下来,会要多久?
      

  4.   

    wudan8057(十年人生)  哈,谢谢你,
    如果针对你的算法,10W条记录判断下来,会要多久?