table
id  title
1   测试asdf标题1
2   23146asdf标题2如何在查询的时候只显示标题中含有关键字asdf,并显示关键字asdf右边的内容?关键是不知道怎么显示关键字右边的内容。求教,谢谢。

解决方案 »

  1.   


    select id,replace(title,'asdf','') from table where title like '%asdf%'
      

  2.   


    select id,stuff(title,patindex('%asdf%',title),4,'') from table where title like '%asdf%'
      

  3.   

    select id,right(replace(title,'asdf','&'),len(replace(title,'asdf','&'))-charindex('&',replace(title,'asdf','&')))
     from tb where title like '%asdf%'
      

  4.   


    select id,stuff(title,1,patindex('%asdf%',title)+3,'') from table where title like '%asdf%'
    不好意思
      

  5.   


    use tempdb;
    /*
    create table [table]
    (
    id int not null,
    title nvarchar(20) not null
    );
    insert into [table](id,title)
    values
    (1,'测试asdf标题1'),
    (2,'23146asdf标题2');
    */
    select parsename(replace(title,'asdf','.'),1) as [内容]
    from [table]
    where title like '%asdf%';