这个应该怎么处理?

hling 2009-07-08 04:22:59
我有一个表A


id name
1 A
2 BB
3 C
4 E
5 GG
6 ABC



如果有一段文字:“械在地在遥A在夺地有地在”

我如何能找到这段文字含有一个A,提示它的id为1








...全文
24 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
风车呼噜噜 2009-07-08
  • 打赏
  • 举报
回复
长知识了.学习
xiequan2 2009-07-08
  • 打赏
  • 举报
回复
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 行受影响)


*/
hling 2009-07-08
  • 打赏
  • 举报
回复
谢谢,近来脑子大紧,唉
htl258_Tony 2009-07-08
  • 打赏
  • 举报
回复

---------------------------------
-- Author: htl258(Tony)
-- Date : 2009-07-08 16:22:12
---------------------------------
--> 生成测试数据表-tb

if 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 行受影响)
*/
liangCK 2009-07-08
  • 打赏
  • 举报
回复
declare @str varchar(100)
set @str = '一段文件'

select *
from tb
where charindex(name,@str) > 0;
csdyyr 2009-07-08
  • 打赏
  • 举报
回复
select *
from tb
where charindex(name,'械在地在遥A在夺地有地在')>0

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧