我有一个表A
id   name
1     A
2     BB
3     C
4     E
5     GG
6     ABC如果有一段文字:“械在地在遥A在夺地有地在”我如何能找到这段文字含有一个A,提示它的id为1

解决方案 »

  1.   

    select *
    from tb
    where charindex(name,'械在地在遥A在夺地有地在')>0
      

  2.   

    declare @str varchar(100)
    set @str = '一段文件'select *
    from tb
    where charindex(name,@str) > 0;
      

  3.   


    ---------------------------------
    --  Author: htl258(Tony)
    --  Date  : 2009-07-08 16:22:12
    ---------------------------------
    --> 生成测试数据表-tbif not object_id('tb') is null
    drop table tb
    Go
    Create table tb([id] int,[name] nvarchar(3))
    Insert tb
    select 1,'A' union all
    select 2,'BB' union all
    select 3,'C' union all
    select 4,'E' union all
    select 5,'GG' union all
    select 6,'ABC'
    Go
    --Select * from tb-->SQL查询如下:declare @s varchar(200)
    set @s='械在地在遥A在夺地有地在'select id from tb where charindex([name],@s)>0/*
    id
    -----------
    1(1 行受影响)
    */
      

  4.   

    declare @t table(id int,name varchar(50))
    insert into @t 
    select 1,'A' union all
    select 2,'BB' union all
    select 3,'C' union all
    select 4,'E' union all
    select 5,'GG' union all
    select 6,'ABC'  select id, charindex(name,b) pos from (select id,name,'械在地在遥A在夺地有地在' b from @t) tmp where charindex(name,b)>0
    /*
    id          pos
    ----------- -----------
    1           6(1 行受影响)
    */